From 65eb8e99d6dfdfdf419254cbb7e26b7afe426691 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 5 Nov 2023 00:39:45 +0700 Subject: editor: simplify using one contenteditable Using multiple lines of content editable is hard, especially when involving selection, deletion, and managing undo-redo history. --- editor/example.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'editor/example.ts') diff --git a/editor/example.ts b/editor/example.ts index a967045..39efb4c 100644 --- a/editor/example.ts +++ b/editor/example.ts @@ -48,13 +48,23 @@ sudo systemctl status telegraf const opts = { id: "editor", - is_editable: true, - onSelection: (begin: number, end: number) => { - console.log("OnSelection: ", begin, end); - }, + isEditable: true, onSave: (content: string) => { - console.log("OnSave: ", content); + const lines = content.split("\n"); + lines.forEach((line: string, x: number) => { + console.log(`${x}: ${line}`); + }); }, }; const wuiEditor = new WuiEditor(opts); wuiEditor.open(nodeFile); + +const optsro = { + id: "editor-readonly", + isEditable: false, + onSave: (content: string) => { + console.log("OnSave: ", content); + }, +}; +const edro = new WuiEditor(optsro); +edro.open(nodeFile); -- cgit v1.3