Merge pull request 'Feature: Add replace and insert code helpers to codemirror' (#2021) from glossing/insert-code-helper into main

Reviewed-on: https://codeberg.org/uzu/strudel/pulls/2021
This commit is contained in:
Aria 2026-03-15 19:25:56 +01:00
commit 9f19e4616a

View file

@ -444,14 +444,16 @@ export class StrudelMirror {
this.setFontSize(value); this.setFontSize(value);
} }
} }
setCode(code) { replaceCode(code, from, to) {
const changes = { const changes = { from, to, insert: code };
from: 0,
to: this.editor.state.doc.length,
insert: code,
};
this.editor.dispatch({ changes }); this.editor.dispatch({ changes });
} }
insertCode(code, position) {
this.replaceCode(code, position, position);
}
setCode(code) {
this.replaceCode(code, 0, this.editor.state.doc.length);
}
// used for debugging but could serve other purposes // used for debugging but could serve other purposes
getActiveWidgets() { getActiveWidgets() {
return getActiveWidgets(this.editor); return getActiveWidgets(this.editor);