mirror of
https://github.com/penpot/penpot.git
synced 2025-05-30 07:36:13 +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
frontend/text-editor/editor/commands
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* 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 before the caret position and this intention is
|
||||
* not covered by another `inputType` or delete the selection with the
|
||||
* selection collapsing to its start after the deletion.
|
||||
*
|
||||
* @param {InputEvent} event
|
||||
* @param {TextEditor} editor
|
||||
* @param {SelectionController} selectionController
|
||||
*/
|
||||
export function deleteContentBackward(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: 'backward' });
|
||||
}
|
||||
|
||||
// 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.focusOffset > 0) {
|
||||
return selectionController.removeBackwardText();
|
||||
|
||||
// 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.focusAtStart
|
||||
) {
|
||||
return selectionController.mergeBackwardParagraph();
|
||||
|
||||
// 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
|
||||
) {
|
||||
return selectionController.removeBackwardParagraph();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue