Closed marcellmars closed 4 years ago
Plan is to switch to easymde (https://github.com/go-gitea/gitea/pull/9973), I guess it can be exposed via window.easymde = [...editors]
then. Array because I think they can appear multiple times on the same page.
Returning to this now that monaco is being used:
it would be great if the editor
that is created here, and which is returned from createCodeEditor()
could be exposed (for example, to Javascript in custom templates).
But it's just thrown away here:
await createCodeEditor($editArea[0], $editFilename[0], previewFileModes);
Most of the customizations described in the Monaco Editor Playground are not possible without the editor
I'll look into that. Will probably be an array window.editors
.
SimpleMDE will eventually go away (probably replaced by a textarea), see https://github.com/go-gitea/gitea/issues/10729.
https://github.com/go-gitea/gitea/pull/11739 will fix this. The only tricky part is because the editor is lazy-loaded, you'll need to wait until it is done loading, for example polling for it:
function waitForEditor() {
return new Promise(resolve => {
const interval = setInterval(() => {
if (window.codeEditors && window.codeEditors.length) {
clearInterval(interval);
resolve(window.codeEditors);
}
}, 500);
});
}
for (const editor of await waitForEditor()) {
console.log(editor);
}
[x]
):Description
I think exposing simpleMDEditor as Javascript object from web_src/js/index.js could be very useful for customizing Gitea.
I added this function to web_src/js/index.js:
and that allows me to play with CodeMirror. Fox example:
allowed me to bring popup list after one would use [Alt-u] keyboard shortcut. I am working on a simple UI in which one could use Gitea to maintain Hugo web site and so far it worked very good but for less tech-savvy people in our team I wanted to bring autocomplete for internal links of the Hugo website. This is the way which allows me to do that.
I played with adding these kind of things via custom templates and it worked great.
Screenshots