Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keymap presentation refinements and underlying restructuring + consistent config use #5565

Closed
wants to merge 43 commits into from

Conversation

gibbz00
Copy link
Contributor

@gibbz00 gibbz00 commented Jan 17, 2023

Commit messages explain most of it. Proceeds: #3053

Before After
image image
2023-01-17-170540_screenshot 2023-01-17-170522_screenshot

Command palette:
Should I change the ">" character to a unicode arrow like: → ?
Should I properly escape less than and greater than from lt and gt to < and > respectively?

Infoboxes issues which haven't been touched upon: #5203, #3958

EDIT: Accidentally snuck in #5130, so guess this proceeds that one too, can open up a new PR which leaves it out if needed.

gibbz00 and others added 30 commits January 17, 2023 15:09
Was not implemented correctly as the order was
in the most cases assigned from the values of
an HashMap, which does not guarantee order.
This applied to when a keymap was both
deserialized and merged.

Info box body was then being sorted as a
function of the fallacious `order` property,
and by a method that yielded at worst a time
complexity of at least n^2.

Furthermore, the body contents were inerted
at first by the order of the hash map keys,
in which `order` itself was based on.

Suffice to say that the order property and the
info box sorting algorithm are now removed.
Exist under the wrong (possibly just outdated)
assumption that command descriptions are written
with their KeyTrie name prefixed (Space, View,
Goto etc.). For examle: The command `file_picker`
is assumed to have the description
"Space Open file picker", which is not the case
, nor for any other command description.
BTree was being used to store a list of keyevents
for a given command. This list was only iterated
over twice to in the end be converted to a Vec.

Better to just use a Vec from start given the use-
case.
Infobox body was being filled with description
then KeyEvent list to only later be iterated over
for the purpose of flippingin this order.
Vec<KeyEvent> was being created as an
intermediary into Info.rs for it to be
converted into a comma separated string.

This commit removes this intermediate step
but also the single purpose from_keymap
public function in Info.rs, as it is no
longer needed.
* Descriptive naming and correct use of data structure terminology
  example translations:
    keymap.reverse_map -> keymap.command_list
    keytrienode -> keytrie (struct)
      search->traverse
      merge->merge_keytrie
    keytrie -> keytrienode (enum describing node variants)
      Leaf -> MappableCommand
      Sequence -> CommandSequence
      Node -> KeyTrie
      (A leaf is a node, and the sequence was also a node.
	  So old naming made absolutely no sense whatsoever.)
* Splitting parts of the keymap.rs file into
  {keytrienode, keytrie, keymaps, tests}.rs.
  (Should be self-explanatory by looking at the old keymap.rs.)
* Removed KeytrieNode enum functions node(&self) -> Option<&KeyTrie>
  and node_mut(&mut self) -> Option<&mut KeyTrie> from KeyTrieNode
  as they served no purpose that could not be used from elsewhere.
  Was also a bit strange to return a "parent struct" from an enum
  "building block".
* Removed getters that could be achieved by making fields public for
  now. (E.g .root(), .map(), .name())
* Removed keymap.merge() and keytrienode.merge_nodes()
  All merging could be handled by keytrie.merge() and
  keymaps.merge_with_default(), unnecessary to have a second
  unused system that does about the same thing.
  We also don't want functions that can cause panics as
  merge_nodes() could.
* Initial simplification and formatting of command palette.
  Formatting is done during the creation of the command lists,
  removes the need for the creation and and traversal of an
  intermediary Vec<Vec<String>>.
  Keyevent formatting changed from "(<space>w<C-q>)" to ["space>w>C-q"].
  Clarifying how commands are triggered by moving through
  submenus/keytries.
For it not to be confused with the upcoming ":help"
feature.
Makes sure:
j, C-j, down
k, up, C-k

Appears as:
j, C-j, down
k, C-k, up

Even though "up" is shorter than "C-k"
Sort duration calculations averaged to about
0.04 ms when opening the lager infoboxes.
* Elaborated on test descriptions
* Removed duplicate unit test
* Unified keytrie traversal in tests
* Moved config merging Keymaps to Config
* Removed unused default EditorView function
* Config::merge_in_default_config()
  takes in self as parameter.
It produces, after all, a Keytrie. It would
be a bit like saying: let engine = car!()
* Removed config dir check and creation from helix-term main.rs, it
  was being done in the proceeding line with helix_loader::initialize_config_file()
* Log path setup moved to helix_loader, and setup not done before setting up logging.
  It would create the default log folder even if user specifies thier own log file.
* Fixed helix_loader::config_file() and log_file() assumption of existing parent directory.
Return Ok(0) to main instead of directly doing
process::exit(0) on only some of the args. Makes
it easier to implement special exit handling
before quitting.
* Don't setup config directory twice in main.
* Remove duplicate config loading code and clean
  up main.rs
* RUNTIME_DIR now behaves similar to the other
  runtime files
* lib.rs cleanup
  * merge_toml_values: Moved function explanation
    comment in a function call to its
    documentation.
* RUNTIME_DIR now behaves similar to the other
  runtime files
* lib.rs cleanup
  * merge_toml_values: Moved function explanation
    comment in a function call to its
    documentation.
* slight appalication.rs cleanup
* Reduce use of relative filepaths with a helix_loader::repo_paths.rs
health.rs
* Removed duplicate clipboard provider writeout.
* Removed 'all' flag option but added a 'paths' option.
* Removed check if user config exist or show default
  part as default is always merged with user config.

docgen:
* removed xtask::helper::lang_config(), using
  LanguageConfiguarions::default() instead.
* moved xtask::query_check to xtask::main and made it use
  TSFeature.runtime_filename()
@archseer
Copy link
Member

It looks like the keys are now sorted in the popup? We deliberately keep the order the same as defined in the keymap, because left/right/up/down should be grouped together and not sorted alphabetically for example.

@pascalkuthe pascalkuthe added S-waiting-on-pr Status: This is waiting on another PR to be merged first A-helix-term Area: Helix term improvements labels Jan 17, 2023
@pascalkuthe
Copy link
Member

@gibbz00 could you maybe provide a summary of what exactly this does. There are 43 commits in this PR so reading trough them all is kind of a chore

@gibbz00
Copy link
Contributor Author

gibbz00 commented Jan 17, 2023

It looks like the keys are now sorted in the popup? We deliberately keep the order the same as defined in the keymap, because left/right/up/down should be grouped together and not sorted alphabetically for example.

Sorting only worked when keymap was added by the keymap! macro and not when loaded by user config. Also, arrow keys are often also bound with hjkl keys, which will show first. Order is: one letter -> C keys -> multi-letter. They aren't shown in the images because I have no_op them.

@@ -7,7 +7,7 @@ macro_rules! hashmap {
($($key:expr => $value:expr),*) => {
{
let _cap = hashmap!(@count $($key),*);
let mut _map = ::std::collections::HashMap::with_capacity(_cap);
let mut _map = std::collections::HashMap::with_capacity(_cap);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deliberate for macro hygiene purposes.

Copy link
Contributor Author

@gibbz00 gibbz00 Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm sure, I can revert this. Although I doubt there will be a namespace are namespace collisions with: std::collections::HashMap::with_capacity

::helix_view::input::KeyEvent {
code: ::helix_view::keyboard::KeyCode::$key,
modifiers: ::helix_view::keyboard::KeyModifiers::NONE,
helix_view::input::KeyEvent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto in this file

@archseer
Copy link
Member

Right, but either way the popup should be arranged in definition order. Certain popups like goto are manually ordered by grouping together similar sets of functionality.

For instance w v and t are common operations so they were listed on top. left/right/up/down are now spread across the whole infobox

@gibbz00
Copy link
Contributor Author

gibbz00 commented Jan 17, 2023

Right, but either way the popup should be arranged in definition order. Certain popups like goto are manually ordered by grouping together similar sets of functionality.

For instance w v and t are common operations so they were listed on top. left/right/up/down are now spread across the whole infobox

No config:

image

@@ -68,7 +68,7 @@ impl KeyTrieNode {
}

pub fn infobox(&self) -> Info {
let mut body: Vec<(&str, BTreeSet<KeyEvent>)> = Vec::with_capacity(self.len());
let mut body: Vec<(&str, Vec<KeyEvent>)> = Vec::with_capacity(self.len());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to revert #952

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted images disagree.

@archseer
Copy link
Member

Hmm it could be non-deterministic? I have no config and it's sorting by arrow direction first (not hjkl)

@gibbz00
Copy link
Contributor Author

gibbz00 commented Jan 17, 2023

Hmm it could be non-deterministic? I have no config and it's sorting by arrow direction first (not hjkl)

When using this PR?

@gibbz00
Copy link
Contributor Author

gibbz00 commented Jan 17, 2023

Certain popups like goto are manually ordered by grouping together similar sets of functionality.

I would still argue that it is easier to find the command when they're sorted alphabetically.

image

@gibbz00
Copy link
Contributor Author

gibbz00 commented Jan 17, 2023

@gibbz00 could you maybe provide a summary of what exactly this does. There are 43 commits in this PR so reading trough them all is kind of a chore

@pascalkuthe clean up of keymap, main.rs, docgen.rs, health.rs. It's a large PR so the commits are the summaries. I'm sorry :(

@archseer
Copy link
Member

Alphabetical sort: we had that initially then replaced it, so this is strictly a downgrade. The goto popup is a great example:

  • g is on the top since it's a repetition of the key
  • h/l are grouped together
  • t/c/b are grouped together
  • a/m are grouped together
  • n/p
  • All the jumps that are LSP specific are also grouped

Alphabetical sort is useful if you're trying to find what a specific key does. But the current order is intended to make it easier to find based on functionality. Kakoune also sorts this similarly.

I like some of the cleanup in this PR though so I might start cherry picking changes into master to shrink the size of this PR a bit and make it easier to review. But I'd avoid renaming types just for the sake of clarity where possible: this is a large project with a lot of PRs in queue and any type of renaming can cause merge conflicts on a large portion of them.

@archseer
Copy link
Member

I've merged #5130 and #3053 so they can be rebased out from this PR now

@gibbz00 gibbz00 closed this Jan 19, 2023
@gibbz00 gibbz00 reopened this Jan 19, 2023
@gibbz00
Copy link
Contributor Author

gibbz00 commented Jan 19, 2023

Alphabetical sort is useful if you're trying to find what a specific key does. But the current order is intended to make it easier to find based on functionality.

Ok, I'm starting to see your point. I can put the ordering from the default ordering back, can, but can I add alphabetical sort as a config option? I have a lot of config keybindings and the info boxes become because of that very messy.

I can also send in split PRs, maybe that can help with the review process.

But I'd avoid renaming types just for the sake of clarity where possible: this is a large project with a lot of PRs in queue and any type of renaming can cause merge conflicts on a large portion of them.

Of course, I'll try to limit this unless I strongly feel that the naming is outright deceptive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-waiting-on-pr Status: This is waiting on another PR to be merged first
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants