Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c1d96bb
Update codeit-autocomplete.js
benhatsor Mar 18, 2023
5faa4db
Update client-channel.js
benhatsor Mar 18, 2023
4e750c3
Update full.css
benhatsor Mar 19, 2023
faf17e1
Update live-view.js
benhatsor Mar 19, 2023
d0480ad
Update full.html
benhatsor Mar 19, 2023
e8d3c15
Update full.html
benhatsor Mar 19, 2023
67a2b1b
Update service-worker.js
benhatsor Mar 19, 2023
c84b4e4
Update codeit.js
benhatsor Mar 19, 2023
ac67ea3
Update codeit.js
benhatsor Mar 19, 2023
569f929
Update codeit.js
benhatsor Mar 19, 2023
9246ebe
Update codeit.js
benhatsor Mar 19, 2023
03db577
Update codeit.js
benhatsor Mar 19, 2023
b4da177
Update client-channel.js
benhatsor Mar 20, 2023
766405a
Create link.html
benhatsor Mar 20, 2023
964af07
Update link.html
benhatsor Mar 20, 2023
0981dfc
Rename link.html to _link.html
benhatsor Mar 20, 2023
118a77c
Update full.css
benhatsor Mar 20, 2023
ebe1e93
Update filebrowser.js
benhatsor Mar 21, 2023
9aa1633
Update live-view.js
benhatsor Mar 21, 2023
c1b4773
Update client-channel.js
benhatsor Mar 22, 2023
68e1df8
Update live-view.js
benhatsor Mar 22, 2023
4ae857f
Update client-channel.js
benhatsor Mar 22, 2023
74f0fc7
Update filebrowser.js
benhatsor Mar 22, 2023
2d290c8
Update full.css
benhatsor Mar 22, 2023
398cb4e
Update client-channel.js
benhatsor Mar 22, 2023
be5fecb
Update and rename _link.html to _link-cache.html
benhatsor Mar 22, 2023
4583824
Update _link-cache.html
benhatsor Mar 22, 2023
b8583ce
Update service-worker.js
benhatsor Mar 22, 2023
d5ae8f0
Update and rename api/_link-cache.html to api-link-cache.html
benhatsor Mar 22, 2023
b9a7771
Update link.js
benhatsor Mar 22, 2023
0dc092f
Update link.js
benhatsor Mar 22, 2023
7229806
Update link.js
benhatsor Mar 22, 2023
203d0e5
Update link.js
benhatsor Mar 22, 2023
417a722
Update api-link-cache.html
benhatsor Mar 22, 2023
2f2de8e
Update api-link-cache.html
benhatsor Mar 22, 2023
28f3ce4
Update link.js
benhatsor Mar 22, 2023
07268b4
Update link.js
benhatsor Mar 22, 2023
d10dc2c
Update full.css
benhatsor Mar 22, 2023
31a6a84
Update full.css
benhatsor Mar 22, 2023
783c9e9
Update client-channel.js
benhatsor Mar 22, 2023
4dee4cf
Delete api-link-cache.html
benhatsor Mar 22, 2023
1646cfe
Restore full.html
benhatsor Mar 22, 2023
fc8da2b
Update live-view.js
benhatsor Mar 22, 2023
d444bce
Update client-channel.js
benhatsor Mar 22, 2023
fb8d75a
Update live-view.js
benhatsor Mar 22, 2023
5a6ef6f
Update live-view.js
benhatsor Mar 22, 2023
c91b900
Update live-view.js
benhatsor Mar 22, 2023
46730ef
Update live-view.js
benhatsor Mar 22, 2023
6ef0eb0
Update client-channel.js
benhatsor Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 63 additions & 43 deletions api/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,62 +98,82 @@ const html = `
<link rel="shortcut icon" href="https://codeit.codes/icons/android-app-512.png">
<link rel="apple-touch-icon" href="https://codeit.codes/icons/iphone-app-180.png">

<script src="/api-link-parser.js"></script>
</head>
<body>

<script src="/api-link-parser.js"></script>

<script>

// decode link

const url = new URL(window.location.href).searchParams;

<script>
let link = url.get('url');

const notLiveView = (url.get('live') === 'false' || url.get('l') === 'f');

const isDev = (window.location.hostname === 'dev.codeit.codes');

// decode link

if (link && link.startsWith('https://codeit.codes/api/link?url=')) {

const url = new URL(window.location.href).searchParams;

let link = url.get('url');
link = link.replace('https://codeit.codes/api/link?url=', 'https://cde.run/');

}


const notLiveView = (url.get('live') === 'false' || url.get('l') === 'f');
if (link && link.includes('https:/github.com')) {

const isDev = (window.location.hostname === 'dev.codeit.codes');
link = link.replace('https:/github.com', 'https://github.com');

if (link && link.startsWith('https://codeit.codes/api/link?url=')) {
link = link.replace('https://codeit.codes/api/link?url=', 'https://cde.run/');
}
}


if (link && !link.startsWith('https://cde.run')
&& !link.startsWith('https://dev.cde.run')) {

if (link && link.includes('https:/github.com')) {

link = link.replace('https:/github.com', 'https://github.com');

}
if (!isDev) link = 'https://cde.run/' + link;
else link = 'https://dev.cde.run/' + link;

if (link && !link.startsWith('https://cde.run')
&& !link.startsWith('https://dev.cde.run')) {

if (!isDev) link = 'https://cde.run/' + link;
else link = 'https://dev.cde.run/' + link;

}
}


if (link && link.startsWith('https://cde.run/github.com/')) {

if (link && notLiveView) {

link += '?live=false';

}
link = link.replace('https://cde.run/github.com/', 'https://cde.run/https://github.com/');

if (link) {

const resp = decodeLink(link);
}

// redirect to decoded URL
window.location.replace(resp);

} else {

window.location.replace(window.location.origin);

}
if (link && link.startsWith('https://dev.cde.run/github.com/')) {

link = link.replace('https://dev.cde.run/github.com/', 'https://dev.cde.run/https://github.com/');

}

</script>

if (link && notLiveView) {

</head>
link += '?live=false';

}

if (link) {

const resp = decodeLink(link);

// redirect to decoded URL
window.location.replace(resp);

} else {

window.location.replace(window.location.origin);

}

</script>

</body>
</html>
`;

Expand Down
15 changes: 12 additions & 3 deletions filebrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ async function renderSidebarHTML(pageNum = 1) {

// if item is a file
if (item.type == 'file') {


// get the file's latest version
let file = getLatestVersion(item);

// search for matching eclipsed files
Expand Down Expand Up @@ -3327,8 +3328,16 @@ function setupEditor() {

// show file content in codeit
try {

cd.textContent = decodeUnicode(selectedFile.content);

const fileContent = decodeUnicode(selectedFile.content);

// compare current code with new code
if (hashCode(cd.textContent) !== hashCode(fileContent)) {

// if the code is different, swap it
cd.textContent = fileContent;

}

// change codeit lang
cd.lang = selectedFile.lang;
Expand Down
10 changes: 5 additions & 5 deletions full.css
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ body.expanded .sidebar-toggle svg .left {
overflow-y: overlay;
overscroll-behavior-y: contain;
pointer-events: none;
padding-left: env(safe-area-inset-left);
padding-left: env(safe-area-inset-left, 0px);
box-sizing: border-box;
z-index: 998;
}
Expand Down Expand Up @@ -1107,7 +1107,7 @@ body.mobile .sidebar .header .title .branch-icon.active {
}

.sidebar .header .search-screen .search-input {
width: calc(var(--sidebar-width) - 102px + 38px);
width: calc(var(--sidebar-width) - 102px + 38px - env(safe-area-inset-left, 0px));
white-space: nowrap;
line-height: 20px;
color: #d4d5d7;
Expand All @@ -1121,7 +1121,7 @@ body.mobile .sidebar .header .title .branch-icon.active {
}

.sidebar .header .search-screen:has(> .clear.visible) .search-input {
width: calc(var(--sidebar-width) - 102px);
width: calc(var(--sidebar-width) - 102px - env(safe-area-inset-left, 0px));
}

.sidebar .header .search-screen .search-input:empty::before {
Expand Down Expand Up @@ -1158,7 +1158,7 @@ body.mobile .sidebar .header .title .branch-icon.active {

.sidebar .header.searching .logo {
padding-left: 7px;
max-width: calc(var(--sidebar-width) - 140px - 16px - 7px - 7px - 7px);
max-width: calc(var(--sidebar-width) - 139px - 16px - 7px - 7px - 7px - env(safe-area-inset-left, 0px));
}

.sidebar .header.searching .title .branch {
Expand Down Expand Up @@ -2310,7 +2310,7 @@ body:not(.mobile) .dialog .button:not(:active):hover {
align-items: center;
justify-content: center;
pointer-events: none;
z-index: 1002;
z-index: 1003;
}

.message {
Expand Down
68 changes: 52 additions & 16 deletions lib/codeit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*

codeit.js
v3.1.3
v3.1.4
MIT License

https://codeit.codes
Expand Down Expand Up @@ -456,24 +456,33 @@ class CodeitElement extends HTMLElement {

cd.on('copy', (e) => {

e.preventDefault();

const text = window.getSelection().toString();

if (text === '') return false;


e.clipboardData.setData('text/plain', text);
e.preventDefault();

});

cd.on('paste', (e) => {

e.preventDefault();

let paste = e.clipboardData.getData('text');

if (paste === '') return false;


const selection = window.getSelection();
if (!selection.rangeCount) return false;

if (!selection.getRangeAt(0).collapsed &&
hashCode(paste) === hashCode(selection.toString())) {

selection.getRangeAt(0).collapse();
e.preventDefault();
selection.getRangeAt(0).collapse();
return false;

}
Expand All @@ -488,8 +497,6 @@ class CodeitElement extends HTMLElement {
cd.insert(paste);

recordHistory();

e.preventDefault();

});

Expand Down Expand Up @@ -566,7 +573,7 @@ class CodeitElement extends HTMLElement {

function handleDelNewLine(event) {

if (event.key === 'Backspace' || event.key === 'Delete') {
if (event.key === 'Backspace') {

const before = cd.beforeCursor();

Expand Down Expand Up @@ -824,7 +831,7 @@ class CodeitElement extends HTMLElement {

function handleDelClosingCharacters(event) {

if (event.key === 'Backspace' || event.key === 'Delete') {
if (event.key === 'Backspace') {

const open = cd.options.openBrackets.join('') + cd.options.quot.join('');
const close = cd.options.closeBrackets.join('') + cd.options.quot.join('');
Expand Down Expand Up @@ -1197,18 +1204,45 @@ class CodeitElement extends HTMLElement {

}

function overrideDeleteText(event) {
function overrideDeleteText(e) {

if (event.key === 'Backspace' || event.key === 'Delete') {
// when deleting in large files,
// the browser reparses the element tree and slows down
// override with range.deleteContents() fixes the problem

event.preventDefault();
if (e.key === 'Backspace') {

// when deleting in large files,
// the browser reparses the element tree and slows down
// override with range.deleteContents() fixes the problem
e.preventDefault();

cd.deleteCurrentSelection();

}

if (e.key === 'Delete') {

e.preventDefault();


// get current selection
const s = window.getSelection();
let r0 = s.getRangeAt(0);

// get selection in text content
let textSel = cd.getSelection();

// if selection is empty, select the char after
if (r0.collapsed) {

textSel.end += 1;

cd.setSelection(textSel.start, textSel.end);

}


cd.deleteCurrentSelection();

}

}

Expand All @@ -1217,14 +1251,16 @@ class CodeitElement extends HTMLElement {
// get current selection
const s = window.getSelection();
let r0 = s.getRangeAt(0);

// get selection in text content
let textSel = cd.getSelection();

// if selection is empty, select the char before
if (r0.collapsed) {

cd.setSelection(textSel.start-1, textSel.end);
textSel.start -= 1;

cd.setSelection(textSel.start, textSel.end);

// get current range
r0 = s.getRangeAt(0);
Expand Down
25 changes: 1 addition & 24 deletions lib/plugins/codeit-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ acp.autocomplete = async (lang) => {

// render results in HTML

const resultsExist = acp.utils.resultsExist(results, query);
const resultsExist = (results.length !== 0);

if (resultsExist) {

Expand Down Expand Up @@ -682,29 +682,6 @@ acp.utils.sort = (matches) => {
}


// check if results exist
acp.utils.resultsExist = (results, query) => {

// if there's no results
if (results.length === 0) {

return false;

}

// if query matches result
if (results.length === 1 &&
results[0] === query) {

return false;

}

return true;

}


// show autocomplete menu
acp.utils.showAcpMenu = () => {

Expand Down
Loading