Add JS method to collapse selection in both composer
Collapsing a selection means removing it and keep the cursor at the end. It will be needed by the scribe for "Insert" action where we want to insert a text at the cursor even if the user selected text.
This commit is contained in:
@@ -111,6 +111,16 @@ class HtmlUtils {
|
|||||||
});''',
|
});''',
|
||||||
name: 'onSelectionChange');
|
name: 'onSelectionChange');
|
||||||
|
|
||||||
|
static const collapseSelectionToEnd = (
|
||||||
|
script: '''
|
||||||
|
(() => {
|
||||||
|
const selection = window.getSelection();
|
||||||
|
if (selection) {
|
||||||
|
selection.collapseToEnd()
|
||||||
|
}
|
||||||
|
})();''',
|
||||||
|
name: 'collapseSelectionToEnd');
|
||||||
|
|
||||||
static recalculateEditorHeight({double? maxHeight}) => (
|
static recalculateEditorHeight({double? maxHeight}) => (
|
||||||
script: '''
|
script: '''
|
||||||
const editable = document.querySelector('.note-editable');
|
const editable = document.querySelector('.note-editable');
|
||||||
|
|||||||
@@ -185,6 +185,10 @@ class _WebEditorState extends State<WebEditorWidget> with TextSelectionMixin {
|
|||||||
name: HtmlUtils.registerSelectionChangeListener.name,
|
name: HtmlUtils.registerSelectionChangeListener.name,
|
||||||
script: HtmlUtils.registerSelectionChangeListener.script,
|
script: HtmlUtils.registerSelectionChangeListener.script,
|
||||||
),
|
),
|
||||||
|
WebScript(
|
||||||
|
name: HtmlUtils.collapseSelectionToEnd.name,
|
||||||
|
script: HtmlUtils.collapseSelectionToEnd.script,
|
||||||
|
),
|
||||||
WebScript(
|
WebScript(
|
||||||
name: HtmlUtils.recalculateEditorHeight(maxHeight: maxHeight).name,
|
name: HtmlUtils.recalculateEditorHeight(maxHeight: maxHeight).name,
|
||||||
script: HtmlUtils.recalculateEditorHeight(maxHeight: maxHeight).script,
|
script: HtmlUtils.recalculateEditorHeight(maxHeight: maxHeight).script,
|
||||||
|
|||||||
Reference in New Issue
Block a user