Skip to content

Commit

Permalink
feat(quickopen): Add binds to open in splits to Quick Open (#3733)
Browse files Browse the repository at this point in the history
* First pass of adding different binds for the quick open menu.

* Fix tests, add changelog entry.

* Update bindings.

* Format.

* Rename commands to be Oni2 specific (as there is no VSCode equiv).

* Update docs.
  • Loading branch information
CrossR authored Jul 12, 2021
1 parent d3944d3 commit a6bd89a
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGES_CURRENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- #3705 - Editor: add right click menus
- #3718 - Completion: Add `editor.suggest.itemsToShow` setting (fixes #3712)
- #3736 - Search: add default keys to go to next / previous search result (fixes #3713)
- #3733 - Quick Open: Add bindings to open in splits, not current buffer.

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion bench/lib/FilterJobBench.re
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let createItem = name => {
let ret: Actions.menuItem = {
category: None,
name,
command: () => Oni_Model.Actions.Noop,
command: _ => Oni_Model.Actions.Noop,
icon: None,
highlight: [],
handle: None,
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/configuration/key-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,16 @@ Onivim-specific contexts:

### List / Menu commands

> NOTE: Some of the list select commands may not be fully hooked up yet, such that they may not respect vertical/horizontal opening.
| Default Key Binding | Description | Command |
| --- | --- | --- |
| Up Arrow / Control+P | Move focus up | `list.focusUp` |
| Down Arrow / Control+N | Move focus down | `list.focusDown` |
| Enter | Select current item | `list.select` |
| Shift-Enter | Select current item (vertical open) | `oni.list.selectVertical` |
| Ctrl-x | Select current item (horizontal open) | `oni.list.selectHorizontal` |
| Ctrl-t | Select current item (new tab) | `oni.list.selectNewTab` |

### Search Pane

Expand Down
4 changes: 2 additions & 2 deletions src/Model/Actions.re
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type t =
| ListFocus(int)
| ListFocusUp
| ListFocusDown
| ListSelect
| ListSelect({direction: SplitDirection.t})
| ListSelectBackground
| NewBuffer({direction: SplitDirection.t})
| OpenBufferById({
Expand Down Expand Up @@ -176,7 +176,7 @@ and tick = {
and menuItem = {
category: option(string),
name: string,
command: unit => t,
command: option(SplitDirection.t) => t,
icon: [@opaque] option(IconTheme.IconDefinition.t),
highlight: list((int, int)),
handle: option(int),
Expand Down
27 changes: 26 additions & 1 deletion src/Model/GlobalCommands.re
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,34 @@ module List = {
let focusDown = register("list.focusDown", ListFocusDown);
let focusUp = register("list.focusUp", ListFocusUp);

let select = register("list.select", ListSelect);
let select =
register(
"list.select",
ListSelect({direction: Oni_Core.SplitDirection.Current}),
);

let selectBackground =
register("list.selectBackground", ListSelectBackground);

let selectHorizontal =
register(
"oni.list.selectHorizontal",
ListSelect({direction: Oni_Core.SplitDirection.Horizontal}),
);

let selectVertical =
register(
"oni.list.selectVertical",
ListSelect({
direction: Oni_Core.SplitDirection.Vertical({shouldReuse: false}),
}),
);

let selectNewTab =
register(
"oni.list.selectNewTab",
ListSelect({direction: Oni_Core.SplitDirection.NewTab}),
);
};

module Oni = {
Expand Down
15 changes: 15 additions & 0 deletions src/Model/State.re
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ let defaultKeyBindings =
~command=Commands.List.select.id,
~condition="listFocus" |> WhenExpr.parse,
),
bind(
~key="<S-CR>",
~command=Commands.List.selectVertical.id,
~condition="listFocus" |> WhenExpr.parse,
),
bind(
~key="<C-x>",
~command=Commands.List.selectHorizontal.id,
~condition="listFocus" |> WhenExpr.parse,
),
bind(
~key="<C-t>",
~command=Commands.List.selectNewTab.id,
~condition="listFocus" |> WhenExpr.parse,
),
bind(
~key="<D-Z>",
~command=Commands.undo.id,
Expand Down
24 changes: 14 additions & 10 deletions src/Store/QuickmenuStoreConnector.re
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Internal = {
Actions.{
category: item.category,
name: item.label,
command: () =>
command: _ =>
switch (Command.Lookup.get(item.command, commands)) {
| Some({msg: `Arg0(msg), _}) => msg
| Some({msg: `Arg1(msgf), _}) => msgf(Json.Encode.null)
Expand All @@ -46,7 +46,7 @@ module Internal = {
handle: Some(item.handle),
icon: None,
highlight: [],
command: () => Actions.Noop,
command: _ => Actions.Noop,
};

let commandPaletteItems = (commands, menus, contextKeys) => {
Expand All @@ -69,9 +69,9 @@ module Internal = {
};

let start = () => {
let selectItemEffect = (item: Actions.menuItem) =>
let selectItemEffect = (~dir=None, item: Actions.menuItem) =>
Isolinear.Effect.createWithDispatch(~name="quickmenu.selectItem", dispatch => {
let action = item.command();
let action = item.command(dir);
dispatch(action);
});

Expand Down Expand Up @@ -144,7 +144,7 @@ let start = () => {
Actions.{
category: None,
name,
command: () => {
command: _ => {
Actions.OpenFileByPath(path, SplitDirection.Current, None);
},
icon:
Expand Down Expand Up @@ -431,7 +431,7 @@ let start = () => {
Isolinear.Effect.none,
)

| ListSelect =>
| ListSelect(args) =>
switch (state) {
| Some({variant: Wildmenu(_), _}) => (None, executeVimCommandEffect)

Expand All @@ -451,7 +451,7 @@ let start = () => {

| Some({items, focused: Some(focused), _}) =>
switch (items[focused]) {
| item => (None, selectItemEffect(item))
| item => (None, selectItemEffect(~dir=Some(args.direction), item))
| exception (Invalid_argument(_)) => (state, Isolinear.Effect.none)
}

Expand Down Expand Up @@ -491,7 +491,7 @@ let start = () => {
| ListFocusDown =>
let (newQuickmenu, eff) = Feature_Quickmenu.next(state.newQuickmenu);
({...state, newQuickmenu}, eff);
| ListSelect =>
| ListSelect(_) =>
let (newQuickmenu, eff) =
Feature_Quickmenu.select(state.newQuickmenu);
({...state, newQuickmenu}, eff);
Expand Down Expand Up @@ -575,8 +575,12 @@ let subscriptions = (ripgrep, dispatch) => {
Actions.{
category: None,
name: Path.toRelative(~base=directory, fullPath),
command: () =>
Actions.OpenFileByPath(fullPath, SplitDirection.Current, None),
command: splitDir =>
switch (splitDir) {
| Some(dir) => Actions.OpenFileByPath(fullPath, dir, None)
| None =>
Actions.OpenFileByPath(fullPath, SplitDirection.Current, None)
},
icon:
Component_FileExplorer.getFileIcon(
~languageInfo,
Expand Down
2 changes: 1 addition & 1 deletion src/Store/VimStoreConnector.re
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ let start =
name,
category: None,
icon: None,
command: () => Noop,
command: _ => Noop,
highlight: [],
handle: None,
}
Expand Down
5 changes: 4 additions & 1 deletion src/UI/QuickmenuView.re
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ module Styles = {
let onFocusedChange = index =>
GlobalContext.current().dispatch(ListFocus(index));

let onSelect = _ => GlobalContext.current().dispatch(ListSelect);
let onSelect = _ =>
GlobalContext.current().dispatch(
ListSelect({direction: Oni_Core.SplitDirection.Current}),
);

let progressBar = (~progress, ~theme, ()) => {
let indicator = () => {
Expand Down
2 changes: 1 addition & 1 deletion test/Model/FilterJobTest.re
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("FilterJob", ({describe, _}) => {
Actions.{
category: None,
name,
command: () => Actions.Noop,
command: _ => Actions.Noop,
icon: None,
highlight: [],
handle: None,
Expand Down

0 comments on commit a6bd89a

Please sign in to comment.