-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FireMonkey: Userscript editing and linting #632
Comments
It is similar. Unfortunately, JSHint has been abandoned (last release Nov 11, 2022), therefore it doesn't support newer JS implementations. CodeMirror 6CodeMirror 5 development has slowed down in favour of CodeMirror 6 which uses ESLint. In order to use it in a browser extension, CodeMirror has to be compiled and I haven't found a guide for it yet. See also: |
Howdy @erosman, I wish I could help you, but I've never used javascript outside of a browser. The only helpful thing I found was this small tutorial about bundling codemirror6 using rollup, but one first has to write a JS file and include the needed CM modules there oneself. Maybe that helps a little? |
Sadly, the node.js bundling software create a massive code. It is not only CodeMirror but Eslint & StyleLint that have to be packed. |
Right. But all the way down, this is discussed. For minimizing, one can use
According to the rollup tutorial, it has a plugin for terse which doesn't seem too hard to use on first glance, and tree-shaking is done automagically? I found this link where shaking is discussed a bit (in the bundlers configuration file, set the sideEffects flag to false, or something. This could work?!?). |
@erosman you can also consider monaco editor. https://microsoft.github.io/monaco-editor/ unzip the zip file, copy the But the size is around 3.5MB |
I use VS Code and the Monaco editor is a good editor. |
You are able to use Monaco Editor in a browser extension (at least in Firefox) as I have modified FireMonkey to use it. |
Have you replaced CodeMirror with Monaco and added ESLint & StyleLint, or are you using the built-in Monaco linter? |
Monaco Editor can work like CM5 that just to put the script tag and then run the script. It will load the dependency automatically provided that you have the correct folder path. These are the files in the folder of the AMD bundled minimized version. Put them into your extension's sub-folder. Before adding the script, const vsPath = "/public/lib/monaco-editor/min/vs";
// Setting up Monaco Editor requirements
let require = {
paths: {
vs: vsPath,
},
};
window.require = (window.require || {});
window.require.paths = (window.require.paths || {});
Object.assign(window.require.paths, require.paths); Without the Then you can add the script with src= Afterwards, a global object These are the example codes for the setup. const editorOptions = {
automaticLayout: true,
foldingStrategy: 'indentation',
lineNumbers: 'on',
readOnly: false,
minimap: {
enabled: false,
},
cursorStyle: 'line',
scrollBeyondLastLine: false,
showUnused: true,
showDeprecated: true,
};
const compilerOptions = {
allowNonTsExtensions: true,
checkJs: true,
noImplicitAny: true,
allowJs: true,
noUnusedLocals: false,
noFallthroughCasesInSwitch: false,
noImplicitThis: false,
};
// global settings
monaco.languages.typescript.javascriptDefaults.setCompilerOptions(Object.assign({
target: monaco.languages.typescript.ScriptTarget.ES2018,
}, compilerOptions));
// when the editor is created
monaco.editor.onDidCreateEditor(()=>{
console.log('the monaco editor is created')
})
// the div will be the container of the editor.
// the value is the input code of the editor. You can change it later too
const editor = monaco.editor.create(div, Object.assign({
value: '',
language: 'javascript'
}, editorOptions));
// set the code
editor.getModel().setValue(newCode);
// set global theme (`vs` for light, `vs-dark` for dark)
monaco.editor.setTheme("vs-dark");
// detect code change
editor.onDidChangeModelContent(()=>{
console.log('code changed', editor.getValue())
}); If you consider to support old browsers, you should use 0.30.1 instead. |
From memory, I replaced most (if not all) instances of CM with ME and rework most features that were dependent on CM. As for the linter, I did use Monaco's built-in linter. |
I have a problem that is maybe related to #623: Newer JS syntax is not linted right, e.g. in classes, the private property marker # throws the linter off. A small (non-sensical) example:
Maybe updating the linter solves this? BTW, CodeMirror fixed some small annoyances w.r.t. to drag+move/copy last year, an update that updates CodeMirror would be appreciated in any case.
Finally, CodeMirror apparently can be tweaked to allow autocomplete without pressing ctrl+space, see here for a small working configuration. Since this involves tweaking events, it seems that it can't work in FireMonkey as of now. Could something like this be added as an option in the future?
The text was updated successfully, but these errors were encountered: