Skip to content

Commit 45e3cf6

Browse files
authored
Merge pull request #244 from codeitcodes/patch-1
Patch 1
2 parents ce8f8e5 + 8154a22 commit 45e3cf6

File tree

8 files changed

+111
-44
lines changed

8 files changed

+111
-44
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Codeit is licensed under the GNU-GPL v3 or any later version.
1+
Codeit is licensed under the GNU-GPL v3.
22
For more info, see: https://gnu.org/licenses/gpl-3.0
33
Copyright (C) 2022 Codeit contributors

filebrowser.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,8 @@ async function loadFileInHTML(fileEl, fileSha) {
14221422

14231423
resp = { content: fileSizeText };
14241424

1425+
cd.textContent = '';
1426+
14251427
// if on mobile device
14261428
if (isMobile) {
14271429

@@ -1438,7 +1440,6 @@ async function loadFileInHTML(fileEl, fileSha) {
14381440
} else {
14391441

14401442
liveToggle.classList.add('file-open');
1441-
updateScrollbarArrow();
14421443

14431444
onNextFrame(() => {
14441445
liveView.classList.remove('notransition');
@@ -1583,7 +1584,6 @@ function loadBinaryFileHTML(file, toggled) {
15831584
if (!isMobile) {
15841585

15851586
liveToggle.classList.add('file-open');
1586-
updateScrollbarArrow();
15871587

15881588
}
15891589

@@ -1945,6 +1945,18 @@ sidebarTitle.addEventListener('click', (e) => {
19451945

19461946
sidebar.classList.add('learn');
19471947

1948+
1949+
// if adding a repository
1950+
1951+
const focusedRepo = fileWrapper.querySelector('.repo.focused');
1952+
1953+
if (focusedRepo) {
1954+
1955+
// remove it
1956+
focusedRepo.remove();
1957+
1958+
}
1959+
19481960
/*
19491961
// if there are no modified files
19501962
// and no pending promises
@@ -3010,6 +3022,7 @@ function onEditorScroll() {
30103022

30113023
}
30123024

3025+
30133026
function updateScrollbarArrow() {
30143027

30153028
// if codeit is horizontally scrollable
@@ -3027,6 +3040,10 @@ function updateScrollbarArrow() {
30273040

30283041
}
30293042

3043+
// when codeit resizes, update
3044+
new ResizeObserver(updateScrollbarArrow).observe(cd);
3045+
3046+
30303047
// check for meta key (Ctrl/Command)
30313048
function isKeyEventMeta(event) {
30323049
return event.metaKey || event.ctrlKey;
@@ -3217,8 +3234,6 @@ function setupEditor() {
32173234
cd.on('scroll', onEditorScroll);
32183235
cd.on('caretmove', saveSelectedFileCaretPos);
32193236

3220-
if (!isMobile) cd.on('type', updateScrollbarArrow);
3221-
32223237
// update on screen resize
32233238

32243239
const landscape = window.matchMedia('(orientation: landscape)');
@@ -3372,7 +3387,7 @@ function setupEditor() {
33723387
if (shownMessages.beautifySelect < 2) {
33733388

33743389
// show beautify select message
3375-
showMessage('Try selecting some text.', 3500);
3390+
showMessage('Try selecting some text first.', 4100);
33763391

33773392
// bump counter
33783393
shownMessages.beautifySelect++;
@@ -3440,7 +3455,6 @@ function updateLineNumbersHTML() {
34403455

34413456
if (!isMobile) {
34423457

3443-
updateScrollbarArrow();
34443458
updateLiveViewArrow();
34453459

34463460
}

full.css

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ body.notransition .live-view.file-open {
467467
width: 100%;
468468
height: 100%;
469469
background: #fff;
470+
border: 0;
470471
max-width: unset;
471472
}
472473

@@ -1791,7 +1792,8 @@ body:not(.mobile) .live-view-menu {
17911792
align-items: center;
17921793
justify-content: center;
17931794
pointer-events: none;
1794-
transform: scale(0.94);
1795+
transform: scale(1.08);
1796+
transform: scale(1.075);
17951797
transform-origin: center;
17961798
transition: 0s .18s;
17971799
}
@@ -1809,14 +1811,14 @@ body.mobile .dialog-background {
18091811
.dialog {
18101812
background: var(--deep-midnight-blue);
18111813
color: #dcddde;
1812-
box-shadow: 0 2px 10px 0 rgb(0 0 0 / 20%);
1813-
border: 1px solid rgb(32 34 37 / 60%);
1814+
box-shadow: 0 8px 16px rgb(0 0 0 / 24%);
18141815
border-radius: 11.5px;
18151816
line-height: 1.5;
18161817
opacity: 0;
1817-
padding: 2px;
1818+
padding: 9px;
18181819
transition: 0s .18s, .18s var(--bounce-function) opacity;
18191820
min-width: 170px;
1821+
overflow: hidden;
18201822
}
18211823

18221824
.dialog-wrapper.visible .dialog {
@@ -1832,23 +1834,71 @@ body.mobile .dialog-background {
18321834
}
18331835

18341836
.dialog .button-wrapper {
1837+
position: relative;
18351838
display: flex;
18361839
margin-top: 7px;
18371840
}
18381841

1842+
body.mobile .dialog .button-wrapper {
1843+
margin: -7px;
1844+
margin-top: 8px;
1845+
}
1846+
1847+
body.mobile .dialog .button-wrapper::before {
1848+
content: '';
1849+
position: absolute;
1850+
top: -1px;
1851+
left: 0;
1852+
right: 0;
1853+
height: 1px;
1854+
background: rgb(32 34 37 / 60%);
1855+
transition: inherit;
1856+
pointer-events: none;
1857+
}
1858+
1859+
body.mobile .dialog-wrapper:not(.visible) .button-wrapper::before {
1860+
left: -2px;
1861+
right: -2px;
1862+
}
1863+
18391864
.dialog .button {
18401865
padding: 8px 14px;
18411866
border-radius: 5.75px;
18421867
display: flex;
18431868
justify-content: center;
1869+
position: relative;
18441870
flex: 1;
18451871
}
18461872

1873+
body.mobile .dialog .button {
1874+
border-radius: 0;
1875+
}
1876+
18471877
.dialog .cancel {
18481878
color: hsl(228deg 16% 37%);
18491879
}
18501880

1851-
.dialog-wrapper.one-button .dialog .cancel {
1881+
.dialog-wrapper.one-button .button.cancel {
1882+
display: none;
1883+
}
1884+
1885+
body.mobile .dialog .cancel::after {
1886+
content: '';
1887+
position: absolute;
1888+
top: 0;
1889+
bottom: 0;
1890+
right: -0.5px;
1891+
width: 1px;
1892+
background: rgb(32 34 37 / 60%);
1893+
transition: inherit;
1894+
pointer-events: none;
1895+
}
1896+
1897+
body.mobile .dialog-wrapper:not(.visible) .button.cancel::after {
1898+
bottom: -2px;
1899+
}
1900+
1901+
body.mobile .dialog-wrapper.one-button .button.cancel::after {
18521902
display: none;
18531903
}
18541904

@@ -1868,7 +1918,7 @@ body:not(.mobile) .dialog .button:not(:active):hover {
18681918
.dialog-background {
18691919
position: fixed;
18701920
inset: 0;
1871-
background: rgba(0,0,0,0.85);
1921+
background: hsl(227deg 11% 16% / 40%);
18721922
width: calc(var(--sidebar-width) - 1px);
18731923
opacity: 0;
18741924
transition: .18s var(--bounce-function);

lib/plugins/codeit-autocomplete.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ acp.lang.css.init = () => {
231231
CSSProps.push('overflow');
232232
CSSProps.push('transition');
233233
CSSProps.push('animation');
234+
CSSProps.push('inset');
235+
CSSProps.push('border-radius');
234236
CSSProps.push('-webkit-user-select');
235237

236238
acp.lang.css.props = CSSProps;
@@ -592,6 +594,10 @@ acp.utils.shouldAutocomplete = () => {
592594
if (input !== document.activeElement) return false;
593595

594596
const cursor = input.dropper.cursor();
597+
598+
// if cursor dosen't exist, return
599+
if (!cursor) return false;
600+
595601
const cursorCollapsed = cursor.collapsed;
596602

597603
// if cursor not collapsed, return

lib/plugins/codeit-autolinker.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@
7070
var isMac = navigator.platform.indexOf('Mac') > -1;
7171

7272
env.attributes.href = href.replaceAll('\'','').replaceAll('"','').replaceAll('`','');
73-
env.attributes.onclick = 'if ((event.ctrlKey || event.metaKey) && event.shiftKey) { event.preventDefault(); window.open(this.href, "_blank") }';
73+
74+
env.attributes.onclick = 'if ((event.ctrlKey || event.metaKey) && event.shiftKey) { event.preventDefault(); window.open(this.href, "_blank") }';
7475
env.attributes.title = isMac ? '⌘ + ⇧ + click to open link' : 'Ctrl + Shift + click to open link';
7576

76-
// Silently catch any error thrown by decodeURIComponent (#1186)
77+
// silently catch any error thrown by decodeURIComponent
7778
try {
7879
env.content = decodeURIComponent(env.content);
79-
} catch (e) { /* noop */ }
80+
} catch (e) {}
8081
}
8182
}
8283
});

live-view/live-view.js

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,6 @@ async function setupLiveView() {
355355
// update line numbers
356356
updateLineNumbersHTML();
357357

358-
// if on desktop
359-
if (!isMobile) {
360-
361-
// update scrollbar arrow
362-
updateScrollbarArrow();
363-
364-
}
365-
366358
}
367359

368360
}
@@ -1014,11 +1006,8 @@ async function handleLiveViewRequest(requestPath) {
10141006
async function renderLiveViewHTML(file) {
10151007

10161008
// if iOS version is lower than minimum
1017-
1018-
const isSafariWithMac = (navigator.userAgent.toLowerCase().includes('safari')
1019-
&& !navigator.userAgent.toLowerCase().includes('chrome'));
1020-
1021-
if (isSafariWithMac) {
1009+
1010+
if (isSafari) {
10221011

10231012
const safariVersion = Number(navigator.userAgent.split('Version/')[1].split(' Safari')[0]);
10241013

@@ -1028,9 +1017,8 @@ async function renderLiveViewHTML(file) {
10281017

10291018
liveView.innerHTML = `
10301019
<div class="prompt">
1031-
<svg style="margin-bottom: 7px;margin-top: -42px;" class="file-svg" viewBox="0 0 752 752" version="1.1" height="146" width="146" xmlns="http://www.w3.org/2000/svg"><defs><clipPath id="a"><path d="m139.21 139.21h473.58v473.58h-473.58z"></path></clipPath></defs><g clip-path="url(#a)"><path d="m356.27 572.35v-38.492c0-10.898 8.7578-19.73 19.73-19.73 10.898 0 19.734 8.7578 19.734 19.73v38.492c93.223-9.2539 167.36-83.395 176.62-176.62h-38.492c-10.898 0-19.73-8.7578-19.73-19.734 0-10.898 8.7578-19.73 19.73-19.73h38.492c-9.2539-93.227-83.395-167.36-176.62-176.62v38.496c0 10.895-8.7578 19.73-19.734 19.73-10.898 0-19.73-8.7578-19.73-19.73v-38.496c-93.227 9.2578-167.36 83.395-176.62 176.62h38.496c10.895 0 19.73 8.7578 19.73 19.73 0 10.898-8.7578 19.734-19.73 19.734h-38.496c9.2578 93.223 83.395 167.36 176.62 176.62zm19.73 40.441c-130.77 0-236.79-106.02-236.79-236.79 0-130.77 106.02-236.79 236.79-236.79 130.78 0 236.79 106.02 236.79 236.79 0 130.78-106.02 236.79-236.79 236.79zm88.371-333.09c10.426-3.1719 16.32 2.6562 13.133 13.133l-37.344 122.7c-3.1758 10.426-14.148 21.434-24.625 24.625l-122.7 37.344c-10.426 3.1719-16.32-2.6562-13.133-13.133l37.344-122.7c3.1719-10.426 14.148-21.438 24.625-24.625zm-111.21 75.098c0.69141-0.20703 1.0391-0.23047 1.2148-0.23828 0.19531-0.36328 0.21875-0.71094 0.42578-1.4023l-21.543 70.793 70.789-21.547c-0.69141 0.21094-1.0391 0.23438-1.2148 0.23828-0.19141 0.36328-0.21484 0.71094-0.42578 1.4023l21.547-70.789z" fill="hsl(223deg 75% 38%)"></path></g></svg>
10321020
<div class="title">Upgrade iOS to run this file</div>
1033-
<a class="desc link" href="https://support.apple.com/en-us/HT204416" target="_blank">Here's how</a>
1021+
<a class="desc link" href="https://support.apple.com/kb/HT204204" target="_blank">Here's how</a>
10341022
</div>
10351023
`;
10361024

@@ -1055,20 +1043,14 @@ async function renderLiveViewHTML(file) {
10551043
if (!workerClientId) await workerInstallPromise;
10561044

10571045

1058-
liveView.innerHTML = '<iframe src="'+ livePath +'?'+ workerClientId +'/" name="Live view" title="Live view" class="live-frame" allow="accelerometer; camera; encrypted-media; display-capture; geolocation; gyroscope; microphone; midi; clipboard-read; clipboard-write" allowfullscreen="true" allowpaymentrequest="true" loading="lazy" sandbox="allow-downloads allow-forms allow-modals allow-pointer-lock allow-popups allow-presentation allow-same-origin allow-scripts allow-top-navigation-by-user-activation" scrolling="yes" frameborder="0"></iframe>';
1046+
liveView.innerHTML = `<iframe src="`+ livePath + '?' + workerClientId + '/' +`" name="Live view" title="Live view" class="live-frame" allow="accelerometer; camera; encrypted-media; display-capture; geolocation; gyroscope; microphone; midi; clipboard-read; clipboard-write; web-share; payment" allowfullscreen="true" allowtransparency="true" loading="eager" sandbox="allow-downloads allow-forms allow-modals allow-pointer-lock allow-popups allow-presentation allow-scripts allow-same-origin"></iframe>`;
10591047

10601048

10611049
liveFile = file;
10621050

10631051

10641052
const liveFrame = liveView.querySelector('.live-frame');
10651053

1066-
liveFrame.contentWindow.addEventListener('DOMContentLoaded', () => {
1067-
1068-
liveFrame.contentWindow.history.replaceState({}, 'Live view', livePath);
1069-
1070-
});
1071-
10721054
liveFrame.contentWindow.addEventListener('load', () => {
10731055

10741056
liveView.classList.add('loaded');

utils.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function stopLoading() {
109109

110110
let messageTimeout;
111111

112-
function showMessage(message, duration) {
112+
let showMessage = (message, duration) => {
113113

114114
// if message includes an icon
115115
if (message.icon) {
@@ -158,15 +158,15 @@ function showMessage(message, duration) {
158158

159159
}
160160

161-
function hideMessage() {
161+
let hideMessage = () => {
162162
messageEl.classList.remove('visible');
163163
}
164164

165165

166166

167167
// show dialog
168168

169-
function showDialog(confirmHandler, titleText, confirmText, showOneButton = false) {
169+
let showDialog = (confirmHandler, titleText, confirmText, showOneButton = false) => {
170170

171171
return new Promise(resolve => {
172172

@@ -227,7 +227,7 @@ function showDialog(confirmHandler, titleText, confirmText, showOneButton = fals
227227

228228
}
229229

230-
function hideDialog() {
230+
let hideDialog = () => {
231231

232232
// hide dialog
233233
dialogWrapper.classList.remove('visible');
@@ -325,7 +325,7 @@ window.addEventListener('offline', () => { isOffline = true });
325325

326326
let isPersistStorage = false;
327327

328-
async function checkPersistStorage() {
328+
let checkPersistStorage = async () => {
329329

330330
if (navigator.storage && navigator.storage.persist) {
331331

@@ -345,6 +345,20 @@ async function checkPersistStorage() {
345345
checkPersistStorage();
346346

347347

348+
// escape HTML
349+
let escapeHTML = (str) => {
350+
351+
const p = document.createElement('p');
352+
p.appendChild(document.createTextNode(str));
353+
354+
let resp = p.innerHTML;
355+
resp = resp.replaceAll(/"/g, "&quot;").replaceAll(/'/g, "&#039;");
356+
357+
return resp;
358+
359+
}
360+
361+
348362
// base64 encode/decode
349363

350364
let encodeUnicode = (str) => {

worker/client-channel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
// update worker name when updating worker
7-
const WORKER_NAME = 'codeit-worker-v615';
7+
const WORKER_NAME = 'codeit-worker-v616';
88

99

1010
// internal paths

0 commit comments

Comments
 (0)