feat: add double-click to expand/collapse large paste placeholders (#17471)

This commit is contained in:
Jack Wotherspoon
2026-01-26 21:59:09 -05:00
committed by GitHub
parent 5cf06503c8
commit a79051d9f8
11 changed files with 1024 additions and 61 deletions

View File

@@ -10,6 +10,7 @@ import {
getPositionFromOffsets,
replaceRangeInternal,
pushUndo,
detachExpandedPaste,
isWordCharStrict,
isWordCharWithCombining,
isCombiningMark,
@@ -105,7 +106,7 @@ export function handleVimAction(
}
if (endRow !== cursorRow || endCol !== cursorCol) {
const nextState = pushUndo(state);
const nextState = detachExpandedPaste(pushUndo(state));
return replaceRangeInternal(
nextState,
cursorRow,
@@ -135,7 +136,7 @@ export function handleVimAction(
}
if (startRow !== cursorRow || startCol !== cursorCol) {
const nextState = pushUndo(state);
const nextState = detachExpandedPaste(pushUndo(state));
return replaceRangeInternal(
nextState,
startRow,
@@ -188,7 +189,7 @@ export function handleVimAction(
}
if (endRow !== cursorRow || endCol !== cursorCol) {
const nextState = pushUndo(state);
const nextState = detachExpandedPaste(pushUndo(state));
return replaceRangeInternal(
nextState,
cursorRow,
@@ -211,7 +212,7 @@ export function handleVimAction(
if (totalLines === 1 || linesToDelete >= totalLines) {
// If there's only one line, or we're deleting all remaining lines,
// clear the content but keep one empty line (text editors should never be completely empty)
const nextState = pushUndo(state);
const nextState = detachExpandedPaste(pushUndo(state));
return {
...nextState,
lines: [''],
@@ -221,7 +222,7 @@ export function handleVimAction(
};
}
const nextState = pushUndo(state);
const nextState = detachExpandedPaste(pushUndo(state));
const newLines = [...nextState.lines];
newLines.splice(cursorRow, linesToDelete);
@@ -243,7 +244,7 @@ export function handleVimAction(
if (lines.length === 0) return state;
const linesToChange = Math.min(count, lines.length - cursorRow);
const nextState = pushUndo(state);
const nextState = detachExpandedPaste(pushUndo(state));
const { startOffset, endOffset } = getLineRangeOffsets(
cursorRow,
@@ -269,7 +270,7 @@ export function handleVimAction(
case 'vim_change_to_end_of_line': {
const currentLine = lines[cursorRow] || '';
if (cursorCol < cpLen(currentLine)) {
const nextState = pushUndo(state);
const nextState = detachExpandedPaste(pushUndo(state));
return replaceRangeInternal(
nextState,
cursorRow,
@@ -292,7 +293,7 @@ export function handleVimAction(
// Change N characters to the left
const startCol = Math.max(0, cursorCol - count);
return replaceRangeInternal(
pushUndo(state),
detachExpandedPaste(pushUndo(state)),
cursorRow,
startCol,
cursorRow,
@@ -308,7 +309,7 @@ export function handleVimAction(
if (totalLines === 1) {
const currentLine = state.lines[0] || '';
return replaceRangeInternal(
pushUndo(state),
detachExpandedPaste(pushUndo(state)),
0,
0,
0,
@@ -316,7 +317,7 @@ export function handleVimAction(
'',
);
} else {
const nextState = pushUndo(state);
const nextState = detachExpandedPaste(pushUndo(state));
const { startOffset, endOffset } = getLineRangeOffsets(
cursorRow,
linesToChange,
@@ -344,7 +345,7 @@ export function handleVimAction(
if (state.lines.length === 1) {
const currentLine = state.lines[0] || '';
return replaceRangeInternal(
pushUndo(state),
detachExpandedPaste(pushUndo(state)),
0,
0,
0,
@@ -354,7 +355,7 @@ export function handleVimAction(
} else {
const startRow = Math.max(0, cursorRow - count + 1);
const linesToChange = cursorRow - startRow + 1;
const nextState = pushUndo(state);
const nextState = detachExpandedPaste(pushUndo(state));
const { startOffset, endOffset } = getLineRangeOffsets(
startRow,
linesToChange,
@@ -392,7 +393,7 @@ export function handleVimAction(
// Right
// Change N characters to the right
return replaceRangeInternal(
pushUndo(state),
detachExpandedPaste(pushUndo(state)),
cursorRow,
cursorCol,
cursorRow,
@@ -624,7 +625,7 @@ export function handleVimAction(
if (cursorCol < lineLength) {
const deleteCount = Math.min(count, lineLength - cursorCol);
const nextState = pushUndo(state);
const nextState = detachExpandedPaste(pushUndo(state));
return replaceRangeInternal(
nextState,
cursorRow,
@@ -656,7 +657,7 @@ export function handleVimAction(
case 'vim_open_line_below': {
const { cursorRow, lines } = state;
const nextState = pushUndo(state);
const nextState = detachExpandedPaste(pushUndo(state));
// Insert newline at end of current line
const endOfLine = cpLen(lines[cursorRow] || '');
@@ -672,7 +673,7 @@ export function handleVimAction(
case 'vim_open_line_above': {
const { cursorRow } = state;
const nextState = pushUndo(state);
const nextState = detachExpandedPaste(pushUndo(state));
// Insert newline at beginning of current line
const resultState = replaceRangeInternal(