mirror of
https://github.com/penpot/penpot.git
synced 2025-05-12 15:06:39 +02:00
✨ Import text-editor code into the repository
This commit is contained in:
parent
68397edd4d
commit
04a0d867b0
65 changed files with 11112 additions and 7 deletions
54
frontend/text-editor/editor/commands/deleteContentForward.js
Normal file
54
frontend/text-editor/editor/commands/deleteContentForward.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Copyright (c) KALEIDOS INC
|
||||
*/
|
||||
|
||||
/**
|
||||
* delete the content directly after the caret position and this intention is not covered by
|
||||
* another inputType or delete the selection with the selection collapsing to its end after the deletion
|
||||
*
|
||||
* @param {InputEvent} event
|
||||
* @param {TextEditor} editor
|
||||
* @param {SelectionController} selectionController
|
||||
*/
|
||||
export function deleteContentForward(event, editor, selectionController) {
|
||||
event.preventDefault();
|
||||
// If the editor is empty this is a no op.
|
||||
if (editor.isEmpty) return;
|
||||
|
||||
// If not is collapsed AKA is a selection, then
|
||||
// we removeSelected.
|
||||
if (!selectionController.isCollapsed) {
|
||||
return selectionController.removeSelected({ direction: "forward" });
|
||||
}
|
||||
|
||||
// If we're in a text node and the offset is
|
||||
// greater than 0 (not at the start of the inline)
|
||||
// we simple remove a character from the text.
|
||||
if (selectionController.isTextFocus
|
||||
&& selectionController.focusAtEnd) {
|
||||
return selectionController.mergeForwardParagraph();
|
||||
|
||||
// If we're in a text node but we're at the end of the
|
||||
// paragraph, we should merge the current paragraph
|
||||
// with the following paragraph.
|
||||
} else if (
|
||||
selectionController.isTextFocus &&
|
||||
selectionController.focusOffset >= 0
|
||||
) {
|
||||
return selectionController.removeForwardText();
|
||||
|
||||
// If we're at an inline or a line break paragraph
|
||||
// and there's more than one paragraph, then we should
|
||||
// remove the next paragraph.
|
||||
} else if (
|
||||
(selectionController.isInlineFocus ||
|
||||
selectionController.isLineBreakFocus) &&
|
||||
editor.numParagraphs > 1
|
||||
) {
|
||||
return selectionController.removeForwardParagraph();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue