wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
17.17k stars 774 forks source link

Is there any way to disable copy the selection to the clipboard when focusing on the window? #6126

Closed mau-mauricelim closed 4 weeks ago

mau-mauricelim commented 4 weeks ago

What Operating System(s) are you seeing this problem on?

Windows

Which Wayland compositor or X11 Window manager(s) are you using?

No response

WezTerm version

wezterm 20240203-110809-5046fc22

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

When copying text from another window and focusing back to wezterm by clicking on the window loses my text copied. The single click action seems to copy a single character on the terminal. The selection is too sensitive. 2024-09-12 10-17-15

Is there any way to tweak the config file to achieve the desired behaviour?

To Reproduce

No response

Configuration

-- Pull in the wezterm API
local wezterm = require('wezterm')
local act = wezterm.action

-- This will hold the configuration.
local config = wezterm.config_builder()

-- This is where you actually apply your config choices
config.default_prog = { 'wsl', '--cd', '~' }
config.font = wezterm.font {
  -- Disable ligatures in most fonts
  family = 'JetBrains Mono',
  harfbuzz_features = { 'calt=0', 'clig=0', 'liga=0' },
}
config.font_size = 16
config.window_padding = { left = 5, right = 5, top = 0, bottom = 0 }
config.window_decorations = 'INTEGRATED_BUTTONS|RESIZE'
config.selection_word_boundary = ',│`|:"\' ()[]{}<>\t'
config.enable_scroll_bar = true
config.cursor_thickness = 2
config.audible_bell = 'Disabled'

-- For example, changing the color scheme:
config.color_scheme = 'Campbell (Gogh)'
config.color_schemes = {
  ['Campbell (Gogh)'] = {
    scrollbar_thumb = '9f9f9f',
  },
}

-- Mouse bindings
config.mouse_bindings = {
  -- Right-click to paste
  {
    event = { Down = { streak = 1, button = 'Right' } },
    mods = 'NONE',
    action = wezterm.action_callback(function(window, pane)
      local has_selection = window:get_selection_text_for_pane(pane) ~= ''
      if has_selection then
        window:perform_action(act.CopyTo('ClipboardAndPrimarySelection'), pane)
        window:perform_action(act.ClearSelection, pane)
      else
        window:perform_action(act({ PasteFrom = 'Clipboard' }), pane)
      end
    end),
  },

  -- Single Left Up: Focus window does not copy text
  {
    event = { Up = { streak = 1, button = 'Left' } },
    mods = 'NONE',
    action = act.Multiple({
      act.ClearSelection,
    }),
  },
  -- Single Left Drag to Highlight and Copy
  {
    event = { Drag = { streak = 1, button = 'Left' } },
    mods = 'NONE',
    action = act.Multiple({
      act.ExtendSelectionToMouseCursor("Cell"),
      act.CopyTo('ClipboardAndPrimarySelection'),
    }),
  },
  -- Double click to Copy
  {
    event = { Up = { streak = 2, button = 'Left' } },
    mods = 'NONE',
    action = act.Multiple({
      act.CopyTo('ClipboardAndPrimarySelection'),
      act.ClearSelection,
    }),
  },
  -- Triple click line to Copy
  {
    event = { Up = { streak = 3, button = 'Left' } },
    mods = 'NONE',
    action = act.Multiple({
      act.CopyTo('ClipboardAndPrimarySelection'),
      act.ClearSelection,
    }),
  },
  -- CTRL-Click to open hyperlink
  {
    event = { Up = { streak = 1, button = 'Left' } },
    mods = 'CTRL',
    action = act.OpenLinkAtMouseCursor,
  },
  -- NOTE that binding only the 'Up' event can give unexpected behaviors.
  -- Read more below on the gotcha of binding an 'Up' event only.

  -- Scrolling up while holding CTRL increases the font size
  {
    event = { Down = { streak = 1, button = { WheelUp = 1 } } },
    mods = 'CTRL',
    action = act.IncreaseFontSize,
  },
  -- Scrolling down while holding CTRL decreases the font size
  {
    event = { Down = { streak = 1, button = { WheelDown = 1 } } },
    mods = 'CTRL',
    action = act.DecreaseFontSize,
  },
}

-- Key bindings
config.keys = {
  -- Paste from the clipboard
  { key = 'v', mods = 'CTRL', action = act.PasteFrom 'Clipboard' },
  {
    key = "|",
    mods = 'CTRL|SHIFT',
    action = wezterm.action.SplitHorizontal { domain = 'CurrentPaneDomain' },
  },
  {
    key = "_",
    mods = 'CTRL|SHIFT',
    action = wezterm.action.SplitVertical { domain = 'CurrentPaneDomain' },
  },
}

-- and finally, return the configuration to wezterm
return config

Expected Behavior

I want this behaviour -- Single Left Up: Focus window does not copy text And I still want these behaviours as well: -- Single Left Drag to Highlight and Copy -- Double click to Copy -- Triple click line to Copy Line

Logs

No response

Anything else?

No response

loops commented 4 weeks ago

Hi mau-mauricelim,

You might try:

config.swallow_mouse_click_on_window_focus = true

Mentioned in the docs here:

https://wezfurlong.org/wezterm/config/lua/config/swallow_mouse_click_on_window_focus.html

mau-mauricelim commented 4 weeks ago

Thank you @loops! This is exactly what I was looking for!