Skip to content

Commit 767186f

Browse files
committed
Merge pull request #21 from r-stein/selection_fields
Selections as Fields
2 parents 12d056f + 844db0f commit 767186f

9 files changed

Lines changed: 593 additions & 4 deletions

Default (Linux).sublime-keymap

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,51 @@
1010
{"key": "setting.is_widget", "operator": "equal", "operand": false}
1111
]
1212
},
13-
{ "keys": ["ctrl+alt+f"], "command": "multi_find_all" }
13+
{ "keys": ["ctrl+alt+f"], "command": "multi_find_all" },
14+
{ "keys": ["ctrl+alt+d"], "command": "selection_fields", "args": {"mode": "smart"} },
15+
{ "keys": ["escape"], "command": "selection_fields",
16+
"args": {"mode": "pop"},
17+
"context":
18+
[
19+
{ "key": "is_selection_field" },
20+
{ "key": "selection_fields_escape_enabled" },
21+
// set the default precedence to be less than snippet fields
22+
{ "key": "has_next_field", "operator": "equal", "operand": false },
23+
{ "key": "has_prev_field", "operator": "equal", "operand": false },
24+
{ "key": "panel_visible", "operator": "equal", "operand": false },
25+
{ "key": "overlay_visible", "operator": "equal", "operand": false },
26+
// usually we would use popup_visible, but this is ST3 only
27+
{ "key": "meu_popup_visible_proxy", "operator": "equal", "operand": false },
28+
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
29+
]
30+
},
31+
{ "keys": ["shift+escape"], "command": "selection_fields",
32+
"args": {"mode": "remove"},
33+
"context":
34+
[
35+
{ "key": "is_selection_field" },
36+
{ "key": "selection_fields_escape_enabled" }
37+
]
38+
},
39+
{ "keys": ["tab"], "command": "selection_fields",
40+
"args": {"mode": "smart"},
41+
"context":
42+
[
43+
{ "key": "is_selection_field" },
44+
{ "key": "selection_fields_tab_enabled" },
45+
// set the default precedence to be less than snippet fields
46+
{ "key": "has_next_field", "operator": "equal", "operand": false },
47+
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
48+
]
49+
},
50+
{ "keys": ["shift+tab"], "command": "selection_fields",
51+
"args": {"mode": "cycle", "jump_forward": false },
52+
"context":
53+
[
54+
{ "key": "is_selection_field" },
55+
{ "key": "selection_fields_tab_enabled" },
56+
// set the default precedence to be less than snippet fields
57+
{ "key": "has_prev_field", "operator": "equal", "operand": false }
58+
]
59+
}
1460
]

Default (OSX).sublime-keymap

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,51 @@
1010
{"key": "setting.is_widget", "operator": "equal", "operand": false}
1111
]
1212
},
13-
{ "keys": ["super+alt+j"], "command": "multi_find_all" }
13+
{ "keys": ["super+alt+j"], "command": "multi_find_all" },
14+
{ "keys": ["super+alt+d"], "command": "selection_fields", "args": {"mode": "smart"} },
15+
{ "keys": ["escape"], "command": "selection_fields",
16+
"args": {"mode": "pop"},
17+
"context":
18+
[
19+
{ "key": "is_selection_field" },
20+
{ "key": "selection_fields_escape_enabled" },
21+
// set the default precedence to be less than snippet fields
22+
{ "key": "has_next_field", "operator": "equal", "operand": false },
23+
{ "key": "has_prev_field", "operator": "equal", "operand": false },
24+
{ "key": "panel_visible", "operator": "equal", "operand": false },
25+
{ "key": "overlay_visible", "operator": "equal", "operand": false },
26+
// usually we would use popup_visible, but this is ST3 only
27+
{ "key": "meu_popup_visible_proxy", "operator": "equal", "operand": false },
28+
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
29+
]
30+
},
31+
{ "keys": ["shift+escape"], "command": "selection_fields",
32+
"args": {"mode": "remove"},
33+
"context":
34+
[
35+
{ "key": "is_selection_field" },
36+
{ "key": "selection_fields_escape_enabled" }
37+
]
38+
},
39+
{ "keys": ["tab"], "command": "selection_fields",
40+
"args": {"mode": "smart"},
41+
"context":
42+
[
43+
{ "key": "is_selection_field" },
44+
{ "key": "selection_fields_tab_enabled" },
45+
// set the default precedence to be less than snippet fields
46+
{ "key": "has_next_field", "operator": "equal", "operand": false },
47+
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
48+
]
49+
},
50+
{ "keys": ["shift+tab"], "command": "selection_fields",
51+
"args": {"mode": "cycle", "jump_forward": false },
52+
"context":
53+
[
54+
{ "key": "is_selection_field" },
55+
{ "key": "selection_fields_tab_enabled" },
56+
// set the default precedence to be less than snippet fields
57+
{ "key": "has_prev_field", "operator": "equal", "operand": false }
58+
]
59+
}
1460
]

Default (Windows).sublime-keymap

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,51 @@
1010
{"key": "setting.is_widget", "operator": "equal", "operand": false}
1111
]
1212
},
13-
{ "keys": ["ctrl+alt+f"], "command": "multi_find_all" }
13+
{ "keys": ["ctrl+alt+f"], "command": "multi_find_all" },
14+
{ "keys": ["ctrl+alt+d"], "command": "selection_fields", "args": {"mode": "smart"} },
15+
{ "keys": ["escape"], "command": "selection_fields",
16+
"args": {"mode": "pop"},
17+
"context":
18+
[
19+
{ "key": "is_selection_field" },
20+
{ "key": "selection_fields_escape_enabled" },
21+
// set the default precedence to be less than snippet fields
22+
{ "key": "has_next_field", "operator": "equal", "operand": false },
23+
{ "key": "has_prev_field", "operator": "equal", "operand": false },
24+
{ "key": "panel_visible", "operator": "equal", "operand": false },
25+
{ "key": "overlay_visible", "operator": "equal", "operand": false },
26+
// usually we would use popup_visible, but this is ST3 only
27+
{ "key": "meu_popup_visible_proxy", "operator": "equal", "operand": false },
28+
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
29+
]
30+
},
31+
{ "keys": ["shift+escape"], "command": "selection_fields",
32+
"args": {"mode": "remove"},
33+
"context":
34+
[
35+
{ "key": "is_selection_field" },
36+
{ "key": "selection_fields_escape_enabled" }
37+
]
38+
},
39+
{ "keys": ["tab"], "command": "selection_fields",
40+
"args": {"mode": "smart"},
41+
"context":
42+
[
43+
{ "key": "is_selection_field" },
44+
{ "key": "selection_fields_tab_enabled" },
45+
// set the default precedence to be less than snippet fields
46+
{ "key": "has_next_field", "operator": "equal", "operand": false },
47+
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
48+
]
49+
},
50+
{ "keys": ["shift+tab"], "command": "selection_fields",
51+
"args": {"mode": "cycle", "jump_forward": false },
52+
"context":
53+
[
54+
{ "key": "is_selection_field" },
55+
{ "key": "selection_fields_tab_enabled" },
56+
// set the default precedence to be less than snippet fields
57+
{ "key": "has_prev_field", "operator": "equal", "operand": false }
58+
]
59+
}
1460
]

Default.sublime-commands

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[
22
{ "command": "jump_to_last_region", "caption" : "MultiEditUtils: Jump to last region" },
33
{ "command": "add_last_selection", "caption" : "MultiEditUtils: Add last selection" },
4+
{ "command": "selection_fields", "caption": "MultiEditUtils: Selection as Fields", "args": {"mode": "toggle"} },
45
{ "command": "cycle_through_regions", "caption" : "MultiEditUtils: Cycle through regions" },
56
{ "command": "normalize_region_ends", "caption" : "MultiEditUtils: Normalize region ends" },
67
{ "command": "split_selection", "caption" : "MultiEditUtils: Split selection" },

Main.sublime-menu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
{ "command": "strip_selection"},
1515
{ "command": "remove_empty_regions"},
1616
{ "command": "multi_find_all"},
17+
{ "command": "selection_fields", "caption": "Selection as Fields", "args": {"mode": "toggle"} },
1718
{ "command": "preserve_case"}
1819
]
1920
}

MultiEditUtils.sublime-settings

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"live_split_selection" : true
2+
"live_split_selection" : true,
3+
// whether the tab key should jump to the next field during the selection field mode
4+
"selection_fields_tab_enabled": true,
5+
// whether the escape key should cancel the selection field mode
6+
"selection_fields_escape_enabled": true
37
}

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,46 @@ Similar to the built-in "Quick Find All" functionality, MultiEditUtils provides
7272
![](http://philippotto.github.io/Sublime-MultiEditUtils/screens/08%20multi%20find%20all.gif)
7373

7474

75+
### Use selections as fields
76+
77+
Converts the selections to fields similar to the fields used in snippets. When the `selection_fields` command is executed, all current selections are saved as fields, which can be activated one by one. The first field is activated automatically. You can jump to the next field with **tab** (or the default keybinding) and to the previous field with **shift+tab**. If you jump behind the last field or press **escape** all fields will be converted to proper selections again. If you press **shift+escape** all fields will be removed and the current selection remains unchanged.
78+
79+
![demo_selection_fields](https://cloud.githubusercontent.com/assets/12573621/14402686/17391716-fe3d-11e5-8fba-4e52a4f93459.gif)
80+
81+
You can bind this command to a keybinding by adding the following to your keymap (Change the key to the keybinding you prefer):
82+
83+
``` js
84+
{ "keys": ["alt+d"], "command": "selection_fields" },
85+
```
86+
87+
Although using one keybinding with the default options should be sufficient for most cases, additional modes and arguments are possible. Feel free to ignore or use them as you wish.
88+
89+
Arguments:
90+
91+
- `mode` (`"smart"`) is the executing mode, which defines the executed action. Possible modes are:
92+
+ `"push"` to push the current selection as fields. This will overwrite already pushed fields.
93+
+ `"pop"` to pop the pushed fields as selections
94+
+ `"remove"` to remove the pushed fields without adding them to the selection. This has the same behavior as pop if `only_other` is `true`.
95+
+ `"add"` to add the current selection to the pushed fields
96+
+ `"subtract"` to subtract the current selection from the pushed fields
97+
+ `"smart"` to try to detect whether to push, pop or jump to the next field
98+
+ `"toggle"` to pop if fields are pushed, else push the selections as fields.
99+
+ `"cycle"` to push or go next. This will cycle, i.e. go to the first if the last field is reached, never pops
100+
- `jump_forward` (`true`) can be `true` to jump forward and `false` to jump backward
101+
- `only_other` (`false`) ignores the current selection for pop and go next actions.
102+
103+
Suggestion for more keybindings based on the arguments:
104+
``` js
105+
// default use of selection_fields
106+
{ "keys": ["alt+d"], "command": "selection_fields" },
107+
// jump and remove current selection in selection_fields
108+
{ "keys": ["ctrl+alt+d"], "command": "selection_fields",
109+
"args": {"mode": "smart", "only_other": true} },
110+
// cancel selection_fields and remove current selection
111+
{ "keys": ["ctrl+alt+shift+d"], "command": "selection_fields",
112+
"args": {"mode": "toggle", "only_other": true} },
113+
```
114+
75115
## Installation
76116

77117
Either use [Package Control](https://sublime.wbond.net/installation) and search for `MultiEditUtils` or clone this repository into Sublime Text "Packages" directory.

0 commit comments

Comments
 (0)