-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change behaviors of ⌘A / ⌃A: Extend selection by level (#445)
Change behaviors of ⌘A: Extend selection from current list item to all sublists of current list item, then to the whole list.
- Loading branch information
Showing
2 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { makeEditor, makeRoot, makeSettings } from "../../__mocks__"; | ||
import { SelectAllContent } from "../SelectAllContent"; | ||
|
||
test("when performed the first time, should select the whole line under cursor; when performed the second time, should select all sub-bullets of the cursor line if it is a parent-bullet", () => { | ||
const root = makeRoot({ | ||
editor: makeEditor({ | ||
text: "- item 1\n- item 2\n - item 2.1\n - item 2.2\n- item 3\n", | ||
cursor: { line: 1, ch: 2 }, | ||
}), | ||
settings: makeSettings(), | ||
}); | ||
|
||
const op = new SelectAllContent(root); | ||
|
||
op.perform(); | ||
expect(root.getSelection().anchor.line).toBe(1); | ||
expect(root.getSelection().anchor.ch).toBe(2); | ||
expect(root.getSelection().head.line).toBe(1); | ||
expect(root.getSelection().head.ch).toBe(8); | ||
|
||
op.perform(); | ||
expect(root.getSelection().anchor.line).toBe(1); | ||
expect(root.getSelection().anchor.ch).toBe(2); | ||
expect(root.getSelection().head.ch).toBe(14); | ||
expect(root.getSelection().head.line).toBe(3); | ||
|
||
op.perform(); | ||
expect(root.getSelection().anchor.line).toBe(0); | ||
expect(root.getSelection().anchor.ch).toBe(0); | ||
expect(root.getSelection().head.line).toBe(4); | ||
expect(root.getSelection().head.ch).toBe(8); | ||
}); | ||
|
||
test("when a whole line is selected and the selected line has no sub-bullets, should select the whole list", () => { | ||
const root = makeRoot({ | ||
editor: makeEditor({ | ||
text: "- item 1\n- item 2\n - item 2.1\n - item 2.2\n- item 3\n", | ||
cursor: { line: 4, ch: 2 }, | ||
}), | ||
settings: makeSettings(), | ||
}); | ||
|
||
const op = new SelectAllContent(root); | ||
|
||
op.perform(); | ||
expect(root.getSelection().anchor.line).toBe(4); | ||
expect(root.getSelection().anchor.ch).toBe(2); | ||
expect(root.getSelection().head.line).toBe(4); | ||
expect(root.getSelection().head.ch).toBe(8); | ||
|
||
op.perform(); | ||
expect(root.getSelection().anchor.line).toBe(0); | ||
expect(root.getSelection().anchor.ch).toBe(0); | ||
expect(root.getSelection().head.line).toBe(4); | ||
expect(root.getSelection().head.ch).toBe(8); | ||
}); |