mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 04:59:34 +01:00
fix(mobile): Send on Enter keeps drafts on every path, Ctrl stays in a held field
- CjkInput remembers which session the field's text belongs to (set by restoreDraft) and clear() stashes a held draft under it, so the paths that drop the active session before the next cleanup (goHome, _replaceTileGrid, _onTileAdoptedElsewhere) keep the answer. discardDraft() drops the owner of a removed session. - Tile focus no longer stashes again for a tile closed from this tab. - With a draft in the field, Ctrl shortcuts (undo, select all, copy) are the field's; they reach the CLI only while it is empty, like Backspace and the arrows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b5ad7afebe
commit
673a656538
5 files changed
+115
-8
No files matched your search
@@ -122,6 +122,14 @@ describe('a held draft survives a reload of the same session', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('tile focus does not stash again for a tile closed from this tab', () => {
|
||||
// removeSession discards the closed session's draft first; a stash after
|
||||
// that would keep it in the map until the page reloads.
|
||||
expect(read('tile-grid.js')).toContain(
|
||||
'if (this.sessions?.has(this.activeSessionId)) CjkInput.stashDraft?.(this.activeSessionId);'
|
||||
);
|
||||
});
|
||||
|
||||
it('tile focus stashes the draft of the tile left and restores the focused one', () => {
|
||||
const tiles = read('tile-grid.js');
|
||||
const start = tiles.indexOf(' _selectTiledSession(sessionId, options = {}) {');
|
||||
|
||||
@@ -365,7 +365,10 @@ describe('CJK input: Send on Enter', () => {
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
CjkInput.restoreDraft('session-a');
|
||||
expect(textarea.value).toBe(PHANTOM + 'half an answer');
|
||||
// Restored once: a second visit does not bring it back again.
|
||||
// Restored once: the stash is consumed, so once the user empties the
|
||||
// field (Esc here) a second visit does not bring it back. A draft still in
|
||||
// the field when the session is left is stashed again by clear().
|
||||
textarea.fire('keydown', { key: 'Escape', keyCode: 27 });
|
||||
CjkInput.clear();
|
||||
CjkInput.restoreDraft('session-a');
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
@@ -409,6 +412,72 @@ describe('CJK input: Send on Enter', () => {
|
||||
expect(textarea.value).toBe(PHANTOM + 'keep me');
|
||||
});
|
||||
|
||||
it('clear() stashes a held draft for the session it was typed for, with no stash call', () => {
|
||||
// goHome(), _replaceTileGrid and _onTileAdoptedElsewhere drop the active
|
||||
// session before the next cleanup, which then has no session to stash for.
|
||||
const { CjkInput, textarea, sent } = load();
|
||||
CjkInput.restoreDraft('session-a');
|
||||
type(textarea, 'typed for a');
|
||||
CjkInput.clear();
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
CjkInput.restoreDraft('session-b');
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
CjkInput.clear();
|
||||
CjkInput.restoreDraft('session-a');
|
||||
expect(textarea.value).toBe(PHANTOM + 'typed for a');
|
||||
expect(sent).toEqual([]);
|
||||
});
|
||||
|
||||
it('a removed session loses its field text: discardDraft drops the owner', () => {
|
||||
const { CjkInput, textarea } = load();
|
||||
CjkInput.restoreDraft('session-a');
|
||||
type(textarea, 'for a closed tile');
|
||||
CjkInput.discardDraft('session-a');
|
||||
expect(CjkInput.draftOwner).toBe(null);
|
||||
CjkInput.clear();
|
||||
CjkInput.restoreDraft('session-a');
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
});
|
||||
|
||||
it('a field still holding text keeps its owner when another session is shown', () => {
|
||||
const { CjkInput, textarea } = load();
|
||||
CjkInput.restoreDraft('session-a');
|
||||
type(textarea, 'still for a');
|
||||
CjkInput.restoreDraft('session-b');
|
||||
expect(CjkInput.draftOwner).toBe('session-a');
|
||||
CjkInput.clear();
|
||||
CjkInput.restoreDraft('session-a');
|
||||
expect(textarea.value).toBe(PHANTOM + 'still for a');
|
||||
});
|
||||
|
||||
it('Ctrl shortcuts stay in the field while it holds a draft', () => {
|
||||
// Ctrl+Z is undo, Ctrl+A select all, Ctrl+C copy: never a control byte to
|
||||
// the CLI while there is a draft to act on.
|
||||
const { textarea, sent } = load();
|
||||
type(textarea, 'draft');
|
||||
for (const key of ['z', 'a', 'c']) {
|
||||
const preventDefault = vi.fn();
|
||||
textarea.fire('keydown', { key, keyCode: key.toUpperCase().charCodeAt(0), ctrlKey: true, preventDefault });
|
||||
expect(preventDefault).not.toHaveBeenCalled();
|
||||
}
|
||||
expect(sent).toEqual([]);
|
||||
});
|
||||
|
||||
it('Ctrl shortcuts reach the CLI from an empty field', () => {
|
||||
const { textarea, sent } = load();
|
||||
const preventDefault = vi.fn();
|
||||
textarea.fire('keydown', { key: 'c', keyCode: 67, ctrlKey: true, preventDefault });
|
||||
expect(preventDefault).toHaveBeenCalled();
|
||||
expect(sent).toEqual(['\x03']);
|
||||
});
|
||||
|
||||
it('live mode keeps sending Ctrl shortcuts with text in the field', () => {
|
||||
const { textarea, sent } = load({ hold: false });
|
||||
textarea.value = PHANTOM + 'x';
|
||||
textarea.fire('keydown', { key: 'c', keyCode: 67, ctrlKey: true });
|
||||
expect(sent).toEqual(['\x03']);
|
||||
});
|
||||
|
||||
it('sends a bare Enter when the field holds only blank lines', () => {
|
||||
const { textarea, sent, prompts } = load();
|
||||
type(textarea, '\n');
|
||||
|
||||
Reference in new issue
Block a user