fix clipboard spam when dragging mouse

This commit is contained in:
David Mo
2025-02-24 12:22:32 -05:00
parent 4e5e4a7c2f
commit 32e2ae92c3

View File

@ -2892,6 +2892,24 @@ pub fn mouseButtonCallback(
}
}
// The selection clipboard is only updated when the left button is released
// when copy on select is enabled.
if (button == .left and
action == .release and
self.config.copy_on_select != .false)
{
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
const prev_ = self.io.terminal.screen.selection;
if (prev_) |prev| {
try self.setSelection(terminal.Selection.init(
prev.start(),
prev.end(),
false,
));
}
}
// Report mouse events if enabled
{
self.renderer_state.mutex.lock();
@ -3029,7 +3047,7 @@ pub fn mouseButtonCallback(
1 => {
// If we have a selection, clear it. This always happens.
if (self.io.terminal.screen.selection != null) {
try self.setSelection(null);
try self.io.terminal.screen.select(null);
try self.queueRender();
}
},
@ -3038,7 +3056,7 @@ pub fn mouseButtonCallback(
2 => {
const sel_ = self.io.terminal.screen.selectWord(pin.*);
if (sel_) |sel| {
try self.setSelection(sel);
try self.io.terminal.screen.select(sel);
try self.queueRender();
}
},
@ -3050,7 +3068,7 @@ pub fn mouseButtonCallback(
else
self.io.terminal.screen.selectLine(.{ .pin = pin.* });
if (sel_) |sel| {
try self.setSelection(sel);
try self.io.terminal.screen.select(sel);
try self.queueRender();
}
},
@ -3335,7 +3353,7 @@ pub fn mousePressureCallback(
// to handle state inconsistency here.
const pin = self.mouse.left_click_pin orelse break :select;
const sel = self.io.terminal.screen.selectWord(pin.*) orelse break :select;
try self.setSelection(sel);
try self.io.terminal.screen.select(sel);
try self.queueRender();
}
}
@ -3538,7 +3556,7 @@ fn dragLeftClickDouble(
// Get the word closest to our starting click.
const word_start = screen.selectWordBetween(click_pin, drag_pin) orelse {
try self.setSelection(null);
try self.io.terminal.screen.select(null);
return;
};
@ -3547,20 +3565,20 @@ fn dragLeftClickDouble(
drag_pin,
click_pin,
) orelse {
try self.setSelection(null);
try self.io.terminal.screen.select(null);
return;
};
// If our current mouse position is before the starting position,
// then the selection start is the word nearest our current position.
if (drag_pin.before(click_pin)) {
try self.setSelection(terminal.Selection.init(
try self.io.terminal.screen.select(terminal.Selection.init(
word_current.start(),
word_start.end(),
false,
));
} else {
try self.setSelection(terminal.Selection.init(
try self.io.terminal.screen.select(terminal.Selection.init(
word_start.start(),
word_current.end(),
false,
@ -3592,7 +3610,7 @@ fn dragLeftClickTriple(
} else {
sel.endPtr().* = line.end();
}
try self.setSelection(sel);
try self.io.terminal.screen.select(sel);
}
fn dragLeftClickSingle(
@ -3646,7 +3664,7 @@ fn dragLeftClickSingle(
else
cell_xpos < cell_xboundary;
try self.setSelection(if (selected) terminal.Selection.init(
try self.io.terminal.screen.select(if (selected) terminal.Selection.init(
drag_pin,
drag_pin,
SurfaceMouse.isRectangleSelectState(self.mouse.mods),
@ -3681,7 +3699,7 @@ fn dragLeftClickSingle(
break :start start;
};
try self.setSelection(terminal.Selection.init(
try self.io.terminal.screen.select(terminal.Selection.init(
start,
drag_pin,
SurfaceMouse.isRectangleSelectState(self.mouse.mods),
@ -3696,7 +3714,7 @@ fn dragLeftClickSingle(
// set earlier.
assert(self.io.terminal.screen.selection != null);
const sel = self.io.terminal.screen.selection.?;
try self.setSelection(terminal.Selection.init(
try self.io.terminal.screen.select(terminal.Selection.init(
sel.start(),
drag_pin,
sel.rectangle,
@ -3740,7 +3758,7 @@ fn checkResetSelSwitch(
}
// Nullifying a selection can't fail.
if (reset) self.setSelection(null) catch unreachable;
if (reset) self.io.terminal.screen.select(null) catch unreachable;
}
// Handles how whether or not the drag screen point is before the click point.