Add a method to delete selection content
This commit is contained in:
@@ -122,6 +122,17 @@ class HtmlUtils {
|
||||
})();''',
|
||||
name: 'collapseSelectionToEnd');
|
||||
|
||||
static const deleteSelectionContent = (
|
||||
script: '''
|
||||
(() => {
|
||||
const selection = window.getSelection();
|
||||
if (selection && selection.rangeCount > 0) {
|
||||
const range = selection.getRangeAt(0);
|
||||
range.deleteContents();
|
||||
}
|
||||
})();''',
|
||||
name: 'deleteSelectionContent');
|
||||
|
||||
static recalculateEditorHeight({double? maxHeight}) => (
|
||||
script: '''
|
||||
const editable = document.querySelector('.note-editable');
|
||||
|
||||
@@ -196,6 +196,10 @@ class _WebEditorState extends State<WebEditorWidget> with TextSelectionMixin {
|
||||
name: HtmlUtils.collapseSelectionToEnd.name,
|
||||
script: HtmlUtils.collapseSelectionToEnd.script,
|
||||
),
|
||||
WebScript(
|
||||
name: HtmlUtils.deleteSelectionContent.name,
|
||||
script: HtmlUtils.deleteSelectionContent.script,
|
||||
),
|
||||
WebScript(
|
||||
name: HtmlUtils.recalculateEditorHeight(maxHeight: maxHeight).name,
|
||||
script: HtmlUtils.recalculateEditorHeight(maxHeight: maxHeight).script,
|
||||
|
||||
Reference in New Issue
Block a user