wez / wezterm

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

macOS Sonoma Copy Issues From Wezterm #4512

Open Nezteb opened 1 year ago

Nezteb commented 1 year ago

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

macOS

WezTerm version

wezterm 20231029-184147-bc99181f

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

Often when I am trying to copy text from WezTerm into another app, the copy fails and the clipboard isn't actually updated. I've only noticed this issue after upgrading to macOS 14.1 (Sonoma).

Toward the bottom of this GH issue I copy-pasted some information from the WezTerm Matrix chat room that has some more details.

Unfortunately, the issue is inconsistent and doesn't occur every time, but usually after trying a couple times I can get it to occur again.

Below is a video demo of the bug occurring. It's worth noting that I'm using Nushell, but the same bug happens when using zsh as well.

https://github.com/wez/wezterm/assets/3588798/a52014e6-7524-48f6-b2fb-9bcaccdafad1

To Reproduce

  1. Use a text editing app like VS Code.
  2. Type some text in a document.
  3. Click over to WezTerm and copy some text (only use CMD+C once).
  4. Try to paste that text back in VS Code.
  5. You'll notice that the pasted content is from your previous invocation of the copy shortcut.

Configuration

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

-- This table will hold the configuration
local config = {}
config.debug_key_events = true

-- In newer versions of wezterm, use the config_builder which will
-- help provide clearer error messages
if wezterm.config_builder then
  config = wezterm.config_builder()
end

-- config.font = wezterm.font 'JetBrains Mono'
config.font = wezterm.font 'FiraCode Nerd Font Mono'

-- https://wezfurlong.org/wezterm/colorschemes/d/index.html#dark-pastel
config.color_scheme = 'Dark Pastel'
config.enable_tab_bar = true
config.use_fancy_tab_bar = true
config.hide_tab_bar_if_only_one_tab = true
config.initial_rows = 50
config.initial_cols = 160
config.scrollback_lines = 1000000

config.keys = {
  {
    key = 'k',
    mods = 'CMD',
    action = act.ClearScrollback 'ScrollbackAndViewport',
  }
}

config.window_frame = {
  -- The font used in the tab bar.
  -- Roboto Bold is the default; this font is bundled
  -- with wezterm.
  -- Whatever font is selected here, it will have the
  -- main font setting appended to it to pick up any
  -- fallback fonts you may have used there.
  font = wezterm.font { family = 'Roboto', weight = 'Bold' },
  -- The size of the font in the tab bar.
  -- Default to 10. on Windows but 12.0 on other systems
  font_size = 12.0,
  -- The overall background color of the tab bar when
  -- the window is focused
  active_titlebar_bg = '#333333',
  -- The overall background color of the tab bar when
  -- the window is not focused
  inactive_titlebar_bg = '#333333',
}

config.colors = {
  tab_bar = {
    -- The color of the inactive tab bar edge/divider
    inactive_tab_edge = '#575757',
  },
}

return config

Expected Behavior

A single invocation of CMD+C should copy the selected text in WezTerm to the macOS clipboard.

Logs

The most detailed log I can find has this content:

19:32:32.325  DEBUG  window::os::macos::app > application_will_finish_launching
19:32:32.353  DEBUG  window::os::macos::app > application_open_untitled_file launched=false
19:32:32.354  DEBUG  window::os::macos::app > application_did_finish_launching
19:38:26.646  INFO   wezterm_gui::termwindow > QuitApplication over here (window)

Anything else?

Relevant Matrix messages:

(That last edit was me thinking the latest nightly had resolved the issue for me, but it turns out it did not, hence me creating this GH issue)

feld commented 10 months ago

I will need more time to be certain but i think I solved it with this config

  keys = {
    {
      key = 'C',
      mods = 'CMD',
      action = wezterm.action.CopyTo 'ClipboardAndPrimarySelection',
    },
  },

I know iOS has per-app clipboards and clipboard security things now, so perhaps MacOS Sonoma had similar clipboard changes?

wez commented 10 months ago

wezterm only uses the global pasteboard on macos, so the various clipboard destinations don't change any behavior in wezterm on macos.

wez commented 9 months ago

FWIW, I never use CMD-C to copy in wezterm; the act of selecting the text automatically copies to the clipboard. I wonder if the issue is that trying to update the clipboard twice in quick succession (once from selecting the text, then again when pressing CMD-C) somehow causes this?

hynek commented 9 months ago

JFTR as a lurker: I have the problem that a freshly started WezTerm on macOS Sonoma on an M2 has select to copy work, but when I do OP's steps it stops working until I restart it.

I'm really curious/jealous that it works for you.

My config just in case – it 100% worked before Sonoma. :|

``` local wezterm = require 'wezterm'; return { hyperlink_rules = { -- Linkify things that look like URLs -- The default regex doesn't support port numbers. { regex = "\\b\\w+://(?:[\\w.-]+)\\S*\\b", format = "$0", }, }, color_scheme = "Cai (Gogh)", font = wezterm.font("Berkeley Mono"), font_size = 14, inactive_pane_hsb = { saturation = 0.5, brightness = 0.3, }, window_frame = { font = wezterm.font({family="Helvetica Neue", weight="Bold"}), font_size = 14.0, }, mouse_bindings = { -- Change the default click behavior so that it only selects -- text and doesn't open hyperlinks { event={Up={streak=1, button="Left"}}, mods="NONE", action=wezterm.action.CompleteSelection("PrimarySelection"), }, -- and make Cmd-Click open hyperlinks { event={Up={streak=1, button="Left"}}, mods="SUPER", action=wezterm.action.OpenLinkAtMouseCursor, }, }, leader = { key="k", mods="SUPER", timeout_milliseconds=1000 }, keys = { -- {key="t", mods="LEADER", action=wezterm.action{SpawnTab="CurrentPaneDomain"}}, -- New Tab in HOME directory. {key="t", mods="LEADER", action=wezterm.action.SpawnCommandInNewTab {args={"/opt/homebrew/bin/fish", "-l"}, cwd=wezterm.home_dir}}, {key="t", mods="SUPER", action=wezterm.action.SpawnCommandInNewTab {args={"/opt/homebrew/bin/fish", "-l"}, cwd=wezterm.home_dir}}, -- Tabs {key="LeftArrow", mods="SUPER", action=wezterm.action{ActivateTabRelative=-1}}, {key="RightArrow", mods="SUPER", action=wezterm.action{ActivateTabRelative=1}}, {key="LeftArrow", mods="SHIFT|SUPER", action=wezterm.action{MoveTabRelative=-1}}, {key="RightArrow", mods="SHIFT|SUPER", action=wezterm.action{MoveTabRelative=1}}, -- Panes {key="z", mods="SUPER", action="TogglePaneZoomState"}, {key="d", mods="SUPER", action=wezterm.action{SplitHorizontal={domain="CurrentPaneDomain"}}}, {key="|", mods="LEADER", action=wezterm.action{SplitHorizontal={domain="CurrentPaneDomain"}}}, {key="D", mods="SUPER", action=wezterm.action{SplitVertical={domain="CurrentPaneDomain"}}}, {key="-", mods="LEADER", action=wezterm.action{SplitVertical={domain="CurrentPaneDomain"}}}, {key="DownArrow", mods="META|SUPER", action=wezterm.action{ActivatePaneDirection="Down"}}, {key="j", mods="LEADER", action=wezterm.action{ActivatePaneDirection="Down"}}, {key="UpArrow", mods="META|SUPER", action=wezterm.action{ActivatePaneDirection="Up"}}, {key="k", mods="LEADER", action=wezterm.action{ActivatePaneDirection="Up"}}, {key="LeftArrow", mods="META|SUPER", action=wezterm.action{ActivatePaneDirection="Left"}}, {key="h", mods="LEADER", action=wezterm.action{ActivatePaneDirection="Left"}}, {key="RightArrow", mods="META|SUPER", action=wezterm.action{ActivatePaneDirection="Right"}}, {key="l", mods="LEADER", action=wezterm.action{ActivatePaneDirection="Right"}}, {key = "H", mods = "LEADER", action=wezterm.action{AdjustPaneSize={"Left", 5}}}, {key = "LeftArrow", mods = "LEADER", action=wezterm.action{AdjustPaneSize={"Left", 5}}}, {key = "L", mods = "LEADER", action=wezterm.action{AdjustPaneSize={"Right", 5}}}, {key = "RightArrow", mods = "LEADER", action=wezterm.action{AdjustPaneSize={"Right", 5}}}, {key = "J", mods = "LEADER", action=wezterm.action{AdjustPaneSize={"Down", 5}}}, {key = "DownArrow", mods = "LEADER", action=wezterm.action{AdjustPaneSize={"Down", 5}}}, {key = "K", mods = "LEADER", action=wezterm.action{AdjustPaneSize={"Up", 5}}}, {key = "UpArrow", mods = "LEADER", action=wezterm.action{AdjustPaneSize={"Up", 5}}}, -- Kill off annoying bindings {key="-", mods="CTRL", action="DisableDefaultAssignment"}, {key="_", mods="CTRL|SHIFT", action="DisableDefaultAssignment"}, {key="+", mods="CTRL", action="DisableDefaultAssignment"}, {key="Enter", mods="META", action="DisableDefaultAssignment"}, } } ```
wez commented 9 months ago

Can you confirm that this only happens when you try to CMD-C to copy? If you skip pressing CMD-C, does the selected text copy and paste successfully?

hynek commented 9 months ago

No, it does not. That's the reason why I've started pressing CMD-C in the first place. Is calling this behavior select to copy correct? I've had a very hard time searching for other people having this problem, which is why I've sat on it since Sonoma came out. I can open another bug, but I find it weird, that my select to copy breaks for the same reasons CMD-C becomes flaky. To be explicit: I have both problems.

wez commented 9 months ago

I'm not suggesting that you have a different problem, I'm just trying to understand why it might be happening; the macOS clipboard API is pretty simple and wezterm hasn't changed its use in a long time. For something to change when updating to Sonoma strongly implies that something on the system has changed. I'm also on Sonoma and haven't experienced this, which makes it extra curious.

Are you perhaps also running some kind of clipboard management software? If so, can you try disabling that for a while and see if it might be influencing things?

hynek commented 9 months ago

OK fun observation: my select to copy bug seems to be indeed the same one because now I've tried the obvious and selected the same thing multiple times and it copied! Not always just twice, mind you.


I run BetterTouchTool whose clipboard functionality I don't use and Alfred whose I do use. I've quit both but the behavior is the same.

More experimenting prompted me to quit PopClip too and it seems to repeatably make the problem go away (just excluding WezTerm works too)!

Which is weird, I've been using it since 2011 without problems. :|


I'm not suggesting that you have a different problem, I'm just trying to understand why it might be happening

And I'm just oversharing since I have your attention – sorry. :)