Skip to content

Commit bd53893

Browse files
authored
Merge pull request #257 from codeitcodes/mobile-console
2 parents 414a746 + 6ef0eb0 commit bd53893

File tree

7 files changed

+147
-95
lines changed

7 files changed

+147
-95
lines changed

api/link.js

Lines changed: 63 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -98,62 +98,82 @@ const html = `
9898
<link rel="shortcut icon" href="https://codeit.codes/icons/android-app-512.png">
9999
<link rel="apple-touch-icon" href="https://codeit.codes/icons/iphone-app-180.png">
100100
101-
<script src="/api-link-parser.js"></script>
101+
</head>
102+
<body>
103+
104+
<script src="/api-link-parser.js"></script>
105+
106+
<script>
107+
108+
// decode link
109+
110+
const url = new URL(window.location.href).searchParams;
102111
103-
<script>
112+
let link = url.get('url');
113+
114+
const notLiveView = (url.get('live') === 'false' || url.get('l') === 'f');
115+
116+
const isDev = (window.location.hostname === 'dev.codeit.codes');
104117
105-
// decode link
118+
119+
if (link && link.startsWith('https://codeit.codes/api/link?url=')) {
106120
107-
const url = new URL(window.location.href).searchParams;
108-
109-
let link = url.get('url');
121+
link = link.replace('https://codeit.codes/api/link?url=', 'https://cde.run/');
122+
123+
}
124+
110125
111-
const notLiveView = (url.get('live') === 'false' || url.get('l') === 'f');
126+
if (link && link.includes('https:/github.com')) {
112127
113-
const isDev = (window.location.hostname === 'dev.codeit.codes');
128+
link = link.replace('https:/github.com', 'https://github.com');
114129
115-
if (link && link.startsWith('https://codeit.codes/api/link?url=')) {
116-
117-
link = link.replace('https://codeit.codes/api/link?url=', 'https://cde.run/');
118-
119-
}
130+
}
131+
132+
133+
if (link && !link.startsWith('https://cde.run')
134+
&& !link.startsWith('https://dev.cde.run')) {
120135
121-
if (link && link.includes('https:/github.com')) {
122-
123-
link = link.replace('https:/github.com', 'https://github.com');
124-
125-
}
136+
if (!isDev) link = 'https://cde.run/' + link;
137+
else link = 'https://dev.cde.run/' + link;
126138
127-
if (link && !link.startsWith('https://cde.run')
128-
&& !link.startsWith('https://dev.cde.run')) {
129-
130-
if (!isDev) link = 'https://cde.run/' + link;
131-
else link = 'https://dev.cde.run/' + link;
132-
133-
}
139+
}
140+
141+
142+
if (link && link.startsWith('https://cde.run/github.com/')) {
134143
135-
if (link && notLiveView) {
136-
137-
link += '?live=false';
138-
139-
}
144+
link = link.replace('https://cde.run/github.com/', 'https://cde.run/https://github.com/');
140145
141-
if (link) {
142-
143-
const resp = decodeLink(link);
146+
}
144147
145-
// redirect to decoded URL
146-
window.location.replace(resp);
147-
148-
} else {
149-
150-
window.location.replace(window.location.origin);
151-
152-
}
148+
if (link && link.startsWith('https://dev.cde.run/github.com/')) {
149+
150+
link = link.replace('https://dev.cde.run/github.com/', 'https://dev.cde.run/https://github.com/');
151+
152+
}
153153
154-
</script>
154+
155+
if (link && notLiveView) {
155156
156-
</head>
157+
link += '?live=false';
158+
159+
}
160+
161+
if (link) {
162+
163+
const resp = decodeLink(link);
164+
165+
// redirect to decoded URL
166+
window.location.replace(resp);
167+
168+
} else {
169+
170+
window.location.replace(window.location.origin);
171+
172+
}
173+
174+
</script>
175+
176+
</body>
157177
</html>
158178
`;
159179

filebrowser.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ async function renderSidebarHTML(pageNum = 1) {
509509

510510
// if item is a file
511511
if (item.type == 'file') {
512-
512+
513+
// get the file's latest version
513514
let file = getLatestVersion(item);
514515

515516
// search for matching eclipsed files
@@ -3327,8 +3328,16 @@ function setupEditor() {
33273328

33283329
// show file content in codeit
33293330
try {
3330-
3331-
cd.textContent = decodeUnicode(selectedFile.content);
3331+
3332+
const fileContent = decodeUnicode(selectedFile.content);
3333+
3334+
// compare current code with new code
3335+
if (hashCode(cd.textContent) !== hashCode(fileContent)) {
3336+
3337+
// if the code is different, swap it
3338+
cd.textContent = fileContent;
3339+
3340+
}
33323341

33333342
// change codeit lang
33343343
cd.lang = selectedFile.lang;

full.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ body.expanded .sidebar-toggle svg .left {
705705
overflow-y: overlay;
706706
overscroll-behavior-y: contain;
707707
pointer-events: none;
708-
padding-left: env(safe-area-inset-left);
708+
padding-left: env(safe-area-inset-left, 0px);
709709
box-sizing: border-box;
710710
z-index: 998;
711711
}
@@ -1107,7 +1107,7 @@ body.mobile .sidebar .header .title .branch-icon.active {
11071107
}
11081108

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

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

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

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

11641164
.sidebar .header.searching .title .branch {
@@ -2310,7 +2310,7 @@ body:not(.mobile) .dialog .button:not(:active):hover {
23102310
align-items: center;
23112311
justify-content: center;
23122312
pointer-events: none;
2313-
z-index: 1002;
2313+
z-index: 1003;
23142314
}
23152315

23162316
.message {

lib/codeit.js

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
33
codeit.js
4-
v3.1.3
4+
v3.1.4
55
MIT License
66
77
https://codeit.codes
@@ -456,24 +456,33 @@ class CodeitElement extends HTMLElement {
456456

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

459+
e.preventDefault();
460+
459461
const text = window.getSelection().toString();
462+
463+
if (text === '') return false;
464+
465+
460466
e.clipboardData.setData('text/plain', text);
461-
e.preventDefault();
462467

463468
});
464469

465470
cd.on('paste', (e) => {
471+
472+
e.preventDefault();
466473

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

476+
if (paste === '') return false;
477+
478+
469479
const selection = window.getSelection();
470480
if (!selection.rangeCount) return false;
471481

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

475-
selection.getRangeAt(0).collapse();
476-
e.preventDefault();
485+
selection.getRangeAt(0).collapse();
477486
return false;
478487

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

490499
recordHistory();
491-
492-
e.preventDefault();
493500

494501
});
495502

@@ -566,7 +573,7 @@ class CodeitElement extends HTMLElement {
566573

567574
function handleDelNewLine(event) {
568575

569-
if (event.key === 'Backspace' || event.key === 'Delete') {
576+
if (event.key === 'Backspace') {
570577

571578
const before = cd.beforeCursor();
572579

@@ -824,7 +831,7 @@ class CodeitElement extends HTMLElement {
824831

825832
function handleDelClosingCharacters(event) {
826833

827-
if (event.key === 'Backspace' || event.key === 'Delete') {
834+
if (event.key === 'Backspace') {
828835

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

11981205
}
11991206

1200-
function overrideDeleteText(event) {
1207+
function overrideDeleteText(e) {
12011208

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

1204-
event.preventDefault();
1213+
if (e.key === 'Backspace') {
12051214

1206-
// when deleting in large files,
1207-
// the browser reparses the element tree and slows down
1208-
// override with range.deleteContents() fixes the problem
1215+
e.preventDefault();
1216+
12091217
cd.deleteCurrentSelection();
12101218

12111219
}
1220+
1221+
if (e.key === 'Delete') {
1222+
1223+
e.preventDefault();
1224+
1225+
1226+
// get current selection
1227+
const s = window.getSelection();
1228+
let r0 = s.getRangeAt(0);
1229+
1230+
// get selection in text content
1231+
let textSel = cd.getSelection();
1232+
1233+
// if selection is empty, select the char after
1234+
if (r0.collapsed) {
1235+
1236+
textSel.end += 1;
1237+
1238+
cd.setSelection(textSel.start, textSel.end);
1239+
1240+
}
1241+
1242+
1243+
cd.deleteCurrentSelection();
1244+
1245+
}
12121246

12131247
}
12141248

@@ -1217,14 +1251,16 @@ class CodeitElement extends HTMLElement {
12171251
// get current selection
12181252
const s = window.getSelection();
12191253
let r0 = s.getRangeAt(0);
1220-
1254+
12211255
// get selection in text content
12221256
let textSel = cd.getSelection();
12231257

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

1227-
cd.setSelection(textSel.start-1, textSel.end);
1261+
textSel.start -= 1;
1262+
1263+
cd.setSelection(textSel.start, textSel.end);
12281264

12291265
// get current range
12301266
r0 = s.getRangeAt(0);

lib/plugins/codeit-autocomplete.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ acp.autocomplete = async (lang) => {
104104

105105
// render results in HTML
106106

107-
const resultsExist = acp.utils.resultsExist(results, query);
107+
const resultsExist = (results.length !== 0);
108108

109109
if (resultsExist) {
110110

@@ -682,29 +682,6 @@ acp.utils.sort = (matches) => {
682682
}
683683

684684

685-
// check if results exist
686-
acp.utils.resultsExist = (results, query) => {
687-
688-
// if there's no results
689-
if (results.length === 0) {
690-
691-
return false;
692-
693-
}
694-
695-
// if query matches result
696-
if (results.length === 1 &&
697-
results[0] === query) {
698-
699-
return false;
700-
701-
}
702-
703-
return true;
704-
705-
}
706-
707-
708685
// show autocomplete menu
709686
acp.utils.showAcpMenu = () => {
710687

0 commit comments

Comments
 (0)