Skip to content

Commit 99d6cb7

Browse files
committed
Initial commit
0 parents  commit 99d6cb7

File tree

1,470 files changed

+1186274
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,470 files changed

+1186274
-0
lines changed

index.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!--
2+
~ This file is part of Visual Code Space.
3+
~
4+
~ Visual Code Space is free software: you can redistribute it and/or modify it under the terms of
5+
~ the GNU General Public License as published by the Free Software Foundation, either version 3 of
6+
~ the License, or (at your option) any later version.
7+
~
8+
~ Visual Code Space is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9+
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
~ GNU General Public License for more details.
11+
~
12+
~ You should have received a copy of the GNU General Public License along with Visual Code Space.
13+
~ If not, see <https://www.gnu.org/licenses/>.
14+
-->
15+
16+
<!DOCTYPE html>
17+
<html lang="en">
18+
<head>
19+
<meta charset="UTF-8" />
20+
<meta name="viewport" content="width=device-width, initial-scale=1" />
21+
<title>Editor</title>
22+
<link rel="stylesheet" href="style.css" />
23+
<link
24+
href="https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap"
25+
rel="stylesheet"
26+
/>
27+
</head>
28+
<body>
29+
<div id="container"></div>
30+
31+
<script src="monaco-editor/dev/vs/loader.js"></script>
32+
<script src="main.js"></script>
33+
</body>
34+
</html>

main.js

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
let editor;
2+
let currentValue = "";
3+
4+
require.config({
5+
paths: {
6+
vs: "https://appassets.androidplatform.net/assets/code-oss/editor/monaco-editor/min/vs",
7+
},
8+
});
9+
10+
window.MonacoEnvironment = {
11+
getWorkerUrl: () => proxy,
12+
};
13+
14+
let proxy = URL.createObjectURL(new Blob([`
15+
self.MonacoEnvironment = {
16+
baseUrl: 'https://appassets.androidplatform.net/assets/code-oss/editor/monaco-editor/min/'
17+
};
18+
importScripts('https://appassets.androidplatform.net/assets/code-oss/editor/monaco-editor/min/vs/base/worker/workerMain.js');
19+
`], { type: 'text/javascript' }));
20+
21+
// Create the editor
22+
require(["vs/editor/editor.main"], function () {
23+
editor = monaco.editor.create(document.getElementById("container"), {
24+
value: "",
25+
language: "plaintext",
26+
theme: "vs-dark",
27+
fontFamily: 'JetBrains Mono'
28+
});
29+
30+
window.MonacoAndroid.setCanUndo(editor.getModel().canUndo());
31+
window.MonacoAndroid.setCanRedo(editor.getModel().canRedo());
32+
33+
editor.onDidChangeModelContent(() => {
34+
const newValue = editor.getValue();
35+
if (currentValue !== newValue) {
36+
currentValue = newValue;
37+
window.MonacoAndroid.onTextChanged(newValue);
38+
}
39+
40+
const content = editor.getValue();
41+
const model = editor.getModel();
42+
const isModified = model.getAlternativeVersionId() !== model.getVersionId();
43+
44+
window.updateCursorInfo();
45+
window.MonacoAndroid.setModified(isModified);
46+
window.MonacoAndroid.setValue(content);
47+
window.MonacoAndroid.setCanUndo(model.canUndo());
48+
window.MonacoAndroid.setCanRedo(model.canRedo());
49+
});
50+
51+
window.updateCursorInfo = function () {
52+
const position = editor.getPosition();
53+
window.MonacoAndroid.setLineNumber(position.lineNumber);
54+
window.MonacoAndroid.setColumn(position.column);
55+
};
56+
});
57+
58+
function setText(content) {
59+
if (editor) {
60+
currentValue = content;
61+
editor.setValue(content);
62+
}
63+
}
64+
65+
function setLanguage(language) {
66+
if (editor) {
67+
monaco.editor.setModelLanguage(editor.getModel(), language);
68+
monaco.languages.registerInlineCompletionsProvider(language, {
69+
provideInlineCompletions: async function (model, position, context, token) {
70+
console.log('Provide new completion', position, context, token);
71+
72+
let textBeforeCursor = model.getValueInRange({
73+
startLineNumber: 1,
74+
startColumn: 1,
75+
endLineNumber: position.lineNumber,
76+
endColumn: position.column
77+
});
78+
79+
let textAfterCursor = model.getValueInRange({
80+
startLineNumber: position.lineNumber,
81+
startColumn: position.column,
82+
endLineNumber: model.getLineCount(),
83+
endColumn: model.getLineMaxColumn(model.getLineCount())
84+
});
85+
86+
// Fetch suggestions from Android
87+
const suggestions = await window.MonacoAndroid.onInlineCompletion(language, textBeforeCursor, textAfterCursor);
88+
89+
// Ensure suggestions are valid
90+
const validSuggestions = suggestions ? [{
91+
insertText: suggestions
92+
}] : [];
93+
94+
return {
95+
items: [
96+
...validSuggestions
97+
]
98+
};
99+
},
100+
freeInlineCompletions: function (completions) {
101+
console.log(completions);
102+
},
103+
});
104+
}
105+
}
106+
107+
function setTheme(theme) {
108+
if (editor) {
109+
monaco.editor.setTheme(theme);
110+
}
111+
}
112+
113+
function focusEditor() {
114+
if (editor) {
115+
editor.focus();
116+
}
117+
}
118+
119+
function setEditorOptions(option, value) {
120+
if (editor) {
121+
const options = {};
122+
options[option] = value;
123+
editor.updateOptions(options);
124+
}
125+
}
126+
127+
function setCursorStyle(styleValue) {
128+
const cursorStyleMap = {
129+
1: 'line',
130+
2: 'block',
131+
3: 'underline',
132+
4: 'line-thin',
133+
5: 'block-outline',
134+
6: 'underline-thin'
135+
};
136+
const cursorStyle = cursorStyleMap[styleValue];
137+
if (cursorStyle) {
138+
editor.updateOptions({ cursorStyle });
139+
}
140+
}
141+
142+
function setCursorBlinkingStyle(styleValue) {
143+
const blinkingStyleMap = {
144+
0: 'hidden',
145+
1: 'blink',
146+
2: 'smooth',
147+
3: 'phase',
148+
4: 'expand',
149+
5: 'solid'
150+
};
151+
152+
const cursorBlinking = blinkingStyleMap[styleValue];
153+
if (cursorBlinking) {
154+
editor.updateOptions({ cursorBlinking });
155+
}
156+
}
157+
158+
function applyMinimapOptions(optionsJson) {
159+
try {
160+
const options = JSON.parse(optionsJson);
161+
editor.updateOptions({
162+
minimap: {
163+
enabled: options.enabled,
164+
autohide: options.autohide,
165+
side: options.side,
166+
size: options.size,
167+
showSlider: options.showSlider,
168+
renderCharacters: options.renderCharacters,
169+
maxColumn: options.maxColumn,
170+
scale: options.scale,
171+
showRegionSectionHeaders: options.showRegionSectionHeaders,
172+
showMarkSectionHeaders: options.showMarkSectionHeaders,
173+
sectionHeaderFontSize: options.sectionHeaderFontSize,
174+
sectionHeaderLetterSpacing: options.sectionHeaderLetterSpacing,
175+
},
176+
});
177+
} catch (error) {
178+
console.error("Error applying minimap options:", error);
179+
}
180+
}
181+
182+
function undo() {
183+
if (editor) {
184+
editor.trigger('keyboard', 'undo');
185+
}
186+
}
187+
188+
function redo() {
189+
if (editor) {
190+
editor.trigger('keyboard', 'redo');
191+
}
192+
}
193+
194+
function insert(text, line, column) {
195+
const position = { lineNumber: line, column: column };
196+
editor.executeEdits(null, [
197+
{
198+
range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column),
199+
text: text,
200+
forceMoveMarkers: true
201+
}
202+
]);
203+
}
204+
205+
function simulateKeyPress(key) {
206+
editor.trigger('keyboard', 'type', { text: key });
207+
}
208+
209+
function selectText(startLineNumber, startColumn, endLineNumber, endColumn) {
210+
const range = new monaco.Range(startLineNumber, startColumn, endLineNumber, endColumn);
211+
editor.setSelection(range);
212+
editor.focus();
213+
}
214+
215+
function replaceSelectedText(text) {
216+
const selection = editor.getSelection();
217+
editor.executeEdits(null, [
218+
{
219+
range: selection,
220+
text: text,
221+
forceMoveMarkers: true
222+
}
223+
]);
224+
}

0 commit comments

Comments
 (0)