Skip to content

Commit

Permalink
feat: disable default hotkeys in the default config setup
Browse files Browse the repository at this point in the history
  • Loading branch information
finxxi authored and xixiaofinland committed Aug 8, 2024
1 parent 00c83fa commit e774165
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ require('sf').setup({
-- Unless you want to customize, no need to copy-paste any of these
-- They are applied automatically

-- This plugin has both hotkeys and user commands supplied
-- This flag enable/disable hotkeys while user commands are always enabled
enable_hotkeys = true,
-- This plugin has many default hotkey mappings supplied
-- This flag enable/disable these hotkeys defined
-- It's highly recommended to set this to `false` and define your own key mappings
-- Set to `true` if you don't mind any potential key mapping conflicts with your own
enable_hotkeys = false,

-- When Nvim is initiated, the sf org list is automatically fetched and target_org is set (if available) by `:SF org fetchList`
-- You can set it to `false` and have a manual control
Expand Down Expand Up @@ -157,6 +159,8 @@ require('sf').setup({

This plugin supplies both user commands (`:h user-commands`) and default hotkeys(`:h mapping`).

Note! Default hotkeys are **disabled** by default in the config setting.

### 🖥️ User commands

User commands are categories into two level subcommands (`:SF sub_cmd1 sub_cmd2`) to leverage the `tab`
Expand All @@ -178,10 +182,10 @@ category as screenshot 2
### ⌨️ Default hotkeys

This plugin comes with many default hotkeys (all defined in [this file](./lua/sf/sub/config_user_key.lua)), which may conflict and overwrite your existing hotkeys.
They are supplied to assist new users.
Thus these hotkeys are **disabled** by default in the config setting.

It is recommended to disable these keys and define the ones you use.
They can be disabled in the configuration by setting `enable_hotkeys` to `false`.
It is also recommended to disable them and define the ones as you wish.
The toggling is in the configuration by setting the `enable_hotkeys` option.

### Often used default keys

Expand All @@ -207,7 +211,7 @@ All keys are listed in `:h sf.nvim` or [help.txt file](https://github.com/xixiao
Example:

- If you have [which-key](https://github.com/folke/which-key.nvim) or a similar plugin installed, pressing `<leader>s` will hint to you what keys are enabled as
shown in the screenshot below. Remember that default hotkeys are enabled only inside a sf folder.
shown in the screenshot below. Remember that default hotkeys are **disabled by default.
![Image 003](https://github.com/xixiaofinland/sf.nvim/assets/13655323/85faa8cb-b1df-40dd-a1bf-323f94bbf13c)

<br>
Expand Down
8 changes: 5 additions & 3 deletions lua/sf/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ local default_cfg = {
-- Unless you want to customize, no need to copy-paste any of these
-- They are applied automatically

-- This plugin has both hotkeys and user commands supplied
-- This flag enable/disable hotkeys while user commands are always enabled
enable_hotkeys = true,
-- This plugin has many default hotkey mappings supplied
-- This flag enable/disable these hotkeys defined
-- It's highly recommended to set this to `false` and define your own key mappings
-- Set to `true` if you don't mind any potential key mapping conflicts with your own
enable_hotkeys = false,

-- When Nvim is initiated, the sf org list is automatically fetched and target_org is set (if available) by `:SF org fetchList`
-- You can set it to `false` and have a manual control
Expand Down
19 changes: 18 additions & 1 deletion tests/test_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ end
T['setup()']['has default config'] = function()
eq(child.lua_get('type(vim.g.sf)'), 'table')

expect_config('enable_hotkeys', true)
expect_config('enable_hotkeys', false)
expect_config('fetch_org_list_at_nvim_start', true)
expect_config('hotkeys_in_filetypes', { "apex", "sosl", "soql", "javascript", "html" })
expect_config('types_to_retrieve', { "ApexClass", "ApexTrigger", "StaticResource", "LightningComponentBundle" })
Expand Down Expand Up @@ -133,7 +133,22 @@ T['setup()']['has default code sign config'] = function()
eq(vim.tbl_isempty(child.fn.sign_getdefined("sf_uncovered")), false)
end

T['setup()']['no user-keys by default'] = function()
child.open_in_sf_dir('test.txt')

-- global;
no_nmap('<leader>ss')
no_nmap('<leader>sf')
no_nmap('<leader>so')
no_nmap('<leader>ml')

-- file-level;
no_nmap('<leader>sp')
no_nmap('<leader>sr')
end

T['setup()']['no user-keys when non-sf-project dir'] = function()
child.sf_setup({ enable_hotkeys = true })
child.open_in_non_sf_dir('NonsfProject.cls')

-- global;
Expand All @@ -148,6 +163,7 @@ T['setup()']['no user-keys when non-sf-project dir'] = function()
end

T['setup()']['only global user-keys when sf-project dir but file not in "hotkeys_in_filetypes"'] = function()
child.sf_setup({ enable_hotkeys = true })
child.open_in_sf_dir('test.txt')

-- global;
Expand All @@ -162,6 +178,7 @@ T['setup()']['only global user-keys when sf-project dir but file not in "hotkeys
end

T['setup()']['has all user-keys when opening Apex in sf-project dir'] = function()
child.sf_setup({ enable_hotkeys = true })
child.open_in_sf_dir('SfProject.cls')

-- global;
Expand Down

0 comments on commit e774165

Please sign in to comment.