Skip to content

Commit

Permalink
Replace first cell content if input while on cell selection (#2030)
Browse files Browse the repository at this point in the history
* select first cell content and empty, add undo if change
  • Loading branch information
Andres-CT98 authored Aug 17, 2023
1 parent 8c7fa2b commit f03f701
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { TableCellSelectionState } from '../TableCellSelectionState';
import { updateSelection } from '../utils/updateSelection';
import {
contains,
createRange,
isCtrlOrMetaPressed,
Position,
safeInstanceOf,
Expand Down Expand Up @@ -37,6 +38,7 @@ export function handleKeyDownEvent(
return;
}

const range = editor.getSelectionRangeEx();
if (shiftKey) {
if (!state.firstTarget) {
const pos = editor.getFocusedPosition();
Expand Down Expand Up @@ -70,10 +72,15 @@ export function handleKeyDownEvent(
}
});
} else if (
editor.getSelectionRangeEx()?.type == SelectionRangeTypes.TableSelection &&
range?.type == SelectionRangeTypes.TableSelection &&
(!isCtrlOrMetaPressed(event.rawEvent) || which == Keys.HOME || which == Keys.END)
) {
editor.select(null);
// Select all content in the first cell
const row = range.ranges[0];
const firstCell = row.startContainer.childNodes[row.startOffset];
const children = firstCell.childNodes;
const contentRange = createRange(children[0], children[children.length - 1]);
editor.select(contentRange);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { clearState } from '../utils/clearState';
import { IEditor, Keys, PluginKeyUpEvent } from 'roosterjs-editor-types';
import { isCharacterValue } from 'roosterjs-editor-dom';
import { TableCellSelectionState } from '../TableCellSelectionState';

const IGNORE_KEY_UP_KEYS = [
Expand All @@ -26,6 +27,9 @@ export function handleKeyUpEvent(
!state.preventKeyUp &&
IGNORE_KEY_UP_KEYS.indexOf(which) == -1
) {
if (isCharacterValue(event.rawEvent)) {
editor.addUndoSnapshot();
}
clearState(state, editor);
}
state.preventKeyUp = false;
Expand Down

0 comments on commit f03f701

Please sign in to comment.