Skip to content

Commit 861c41b

Browse files
committed
Fix more bugs
1 parent f1f0e9f commit 861c41b

3 files changed

Lines changed: 59 additions & 8 deletions

File tree

src/subcommands/chat/react/ChatInput.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,16 @@ export const ChatInput = ({
188188
return;
189189
}
190190

191-
// For linux, we need to specifically check for Alt+Arrows so we have these here
192-
if (key.leftArrow === true) {
193-
setUserInputState(previousState => moveCursorWordLeft(previousState));
194-
return;
195-
}
196-
if (key.rightArrow === true) {
197-
setUserInputState(previousState => moveCursorWordRight(previousState));
198-
return;
191+
if (isMac === false) {
192+
// For linux, we need to specifically check for Alt+Arrows so we have these here
193+
if (key.leftArrow === true) {
194+
setUserInputState(previousState => moveCursorWordLeft(previousState));
195+
return;
196+
}
197+
if (key.rightArrow === true) {
198+
setUserInputState(previousState => moveCursorWordRight(previousState));
199+
return;
200+
}
199201
}
200202
// When we press option+fn+delete on macOS, it sends meta+d
201203
// and for linux, alt+d is the alternative to alt+delete for word delete forward

src/subcommands/chat/react/inputReducer.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,25 @@ describe("chatInputStateReducers", () => {
20072007
expect(result.cursorOnSegmentIndex).toBe(0);
20082008
expect(result.cursorInSegmentOffset).toBe(0);
20092009
});
2010+
2011+
it("deletes largePaste when cursor is at trailing placeholder after paste", () => {
2012+
const initialState: ChatUserInputState = {
2013+
segments: [
2014+
{ type: "largePaste", content: "x".repeat(100) },
2015+
{ type: "text", content: "" },
2016+
],
2017+
cursorOnSegmentIndex: 1,
2018+
cursorInSegmentOffset: 0,
2019+
};
2020+
2021+
const result = deleteToLineStart(initialState);
2022+
2023+
expect(result.segments.length).toBe(1);
2024+
expect(result.segments[0].type).toBe("text");
2025+
expect(result.segments[0].content).toBe("");
2026+
expect(result.cursorOnSegmentIndex).toBe(0);
2027+
expect(result.cursorInSegmentOffset).toBe(0);
2028+
});
20102029
});
20112030

20122031
describe("deleteToLineEnd", () => {
@@ -2142,5 +2161,24 @@ describe("chatInputStateReducers", () => {
21422161
expect(result.cursorOnSegmentIndex).toBe(0);
21432162
expect(result.cursorInSegmentOffset).toBe(5);
21442163
});
2164+
2165+
it("deletes largePaste and following text when cursor is at offset 0 of largePaste", () => {
2166+
const initialState: ChatUserInputState = {
2167+
segments: [
2168+
{ type: "largePaste", content: "x".repeat(100) },
2169+
{ type: "text", content: "following text" },
2170+
],
2171+
cursorOnSegmentIndex: 0,
2172+
cursorInSegmentOffset: 0,
2173+
};
2174+
2175+
const result = deleteToLineEnd(initialState);
2176+
2177+
expect(result.segments.length).toBe(1);
2178+
expect(result.segments[0].type).toBe("text");
2179+
expect(result.segments[0].content).toBe("");
2180+
expect(result.cursorOnSegmentIndex).toBe(0);
2181+
expect(result.cursorInSegmentOffset).toBe(0);
2182+
});
21452183
});
21462184
});

src/subcommands/chat/react/inputReducer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,10 @@ export function deleteToLineStart(state: ChatUserInputState): ChatUserInputState
10581058
draft.segments.splice(lineStartPosition.segmentIndex, 1);
10591059
draft.cursorOnSegmentIndex = lineStartPosition.segmentIndex;
10601060
}
1061+
} else if (lineStartSegment !== undefined) {
1062+
// Line start segment is non-text (e.g., largePaste) - remove it
1063+
draft.segments.splice(lineStartPosition.segmentIndex, 1);
1064+
draft.cursorOnSegmentIndex = lineStartPosition.segmentIndex;
10611065
}
10621066

10631067
draft.cursorInSegmentOffset = 0;
@@ -1141,6 +1145,13 @@ export function deleteToLineEnd(state: ChatUserInputState): ChatUserInputState {
11411145
} else {
11421146
currentSegment.content = contentBeforeCursor;
11431147
}
1148+
} else if (currentOffset === 0) {
1149+
// At start of non-text segment - remove it along with everything to line end
1150+
draft.segments.splice(
1151+
currentSegmentIndex,
1152+
lineEndPosition.segmentIndex - currentSegmentIndex + 1,
1153+
);
1154+
return;
11441155
}
11451156

11461157
// Remove segments between cursor and line end (inclusive of line end if different)

0 commit comments

Comments
 (0)