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

Remember selection mode #5966

Open
wangp opened this issue Aug 15, 2024 · 0 comments
Open

Remember selection mode #5966

wangp opened this issue Aug 15, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@wangp
Copy link

wangp commented Aug 15, 2024

Is your feature request related to a problem? Please describe.
I like to initiate a text selection with a single/double/triple left click, then extend the selection (as required) with a single right click. This is much more comfortable than trying to select the text perfectly while holding down the left mouse button.

I managed to implement the behaviour in the Lua config as below, but perhaps it can be done more simply?

mouse_selection_mode = 'Cell'
config.mouse_bindings = {
  -- Single left-click: select cell
  {
    event = { Down = { streak = 1, button = 'Left' } },
    mods = 'NONE',
    action = wezterm.action_callback(function(win, pane)
      mouse_selection_mode = 'Cell'
      win:perform_action(act.SelectTextAtMouseCursor(mouse_selection_mode), pane)
    end)
  },
  -- Double left-click: select word
  {
    event = { Down = { streak = 2, button = 'Left' } },
    mods = 'NONE',
    action = wezterm.action_callback(function(win, pane)
      mouse_selection_mode = 'Word'
      win:perform_action(act.SelectTextAtMouseCursor(mouse_selection_mode), pane)
    end)
  },
  -- Triple left-click: select line
  {
    event = { Down = { streak = 3, button = 'Left' } },
    mods = 'NONE',
    action = wezterm.action_callback(function(win, pane)
      mouse_selection_mode = 'Line'
      win:perform_action(act.SelectTextAtMouseCursor(mouse_selection_mode), pane)
    end)
  },
  -- ALT+Left-click: select block
  {
    event = { Down = { streak = 1, button = 'Left' } },
    mods = 'ALT',
    action = wezterm.action_callback(function(win, pane)
      mouse_selection_mode = 'Block'
      win:perform_action(act.SelectTextAtMouseCursor(mouse_selection_mode), pane)
    end)
  },
  -- Single right-click: extend selection (current mode)
  {
    event = { Down = { streak = 1, button = 'Right' } },
    mods = 'NONE',
    action = wezterm.action_callback(function(win, pane)
      win:perform_action(act.ExtendSelectionToMouseCursor(mouse_selection_mode), pane)
    end)
  },
  {
    event = { Up = { streak = 1, button = 'Right' } },
    mods = 'NONE',
    action = act.CompleteSelection('ClipboardAndPrimarySelection')
  },
}

Describe the solution you'd like
ExtendSelectionToMouseCursor could take a mode (say, "Current" or "LastMode") that refers to the current selection mode. This was suggested previously in #182 and #282 (comment)

@wangp wangp added the enhancement New feature or request label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant