mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
fix clipboard spam when dragging mouse
This commit is contained in:
@ -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
|
// Report mouse events if enabled
|
||||||
{
|
{
|
||||||
self.renderer_state.mutex.lock();
|
self.renderer_state.mutex.lock();
|
||||||
@ -3029,7 +3047,7 @@ pub fn mouseButtonCallback(
|
|||||||
1 => {
|
1 => {
|
||||||
// If we have a selection, clear it. This always happens.
|
// If we have a selection, clear it. This always happens.
|
||||||
if (self.io.terminal.screen.selection != null) {
|
if (self.io.terminal.screen.selection != null) {
|
||||||
try self.setSelection(null);
|
try self.io.terminal.screen.select(null);
|
||||||
try self.queueRender();
|
try self.queueRender();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -3038,7 +3056,7 @@ pub fn mouseButtonCallback(
|
|||||||
2 => {
|
2 => {
|
||||||
const sel_ = self.io.terminal.screen.selectWord(pin.*);
|
const sel_ = self.io.terminal.screen.selectWord(pin.*);
|
||||||
if (sel_) |sel| {
|
if (sel_) |sel| {
|
||||||
try self.setSelection(sel);
|
try self.io.terminal.screen.select(sel);
|
||||||
try self.queueRender();
|
try self.queueRender();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -3050,7 +3068,7 @@ pub fn mouseButtonCallback(
|
|||||||
else
|
else
|
||||||
self.io.terminal.screen.selectLine(.{ .pin = pin.* });
|
self.io.terminal.screen.selectLine(.{ .pin = pin.* });
|
||||||
if (sel_) |sel| {
|
if (sel_) |sel| {
|
||||||
try self.setSelection(sel);
|
try self.io.terminal.screen.select(sel);
|
||||||
try self.queueRender();
|
try self.queueRender();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -3335,7 +3353,7 @@ pub fn mousePressureCallback(
|
|||||||
// to handle state inconsistency here.
|
// to handle state inconsistency here.
|
||||||
const pin = self.mouse.left_click_pin orelse break :select;
|
const pin = self.mouse.left_click_pin orelse break :select;
|
||||||
const sel = self.io.terminal.screen.selectWord(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();
|
try self.queueRender();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3538,7 +3556,7 @@ fn dragLeftClickDouble(
|
|||||||
|
|
||||||
// Get the word closest to our starting click.
|
// Get the word closest to our starting click.
|
||||||
const word_start = screen.selectWordBetween(click_pin, drag_pin) orelse {
|
const word_start = screen.selectWordBetween(click_pin, drag_pin) orelse {
|
||||||
try self.setSelection(null);
|
try self.io.terminal.screen.select(null);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -3547,20 +3565,20 @@ fn dragLeftClickDouble(
|
|||||||
drag_pin,
|
drag_pin,
|
||||||
click_pin,
|
click_pin,
|
||||||
) orelse {
|
) orelse {
|
||||||
try self.setSelection(null);
|
try self.io.terminal.screen.select(null);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
// If our current mouse position is before the starting position,
|
// If our current mouse position is before the starting position,
|
||||||
// then the selection start is the word nearest our current position.
|
// then the selection start is the word nearest our current position.
|
||||||
if (drag_pin.before(click_pin)) {
|
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_current.start(),
|
||||||
word_start.end(),
|
word_start.end(),
|
||||||
false,
|
false,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
try self.setSelection(terminal.Selection.init(
|
try self.io.terminal.screen.select(terminal.Selection.init(
|
||||||
word_start.start(),
|
word_start.start(),
|
||||||
word_current.end(),
|
word_current.end(),
|
||||||
false,
|
false,
|
||||||
@ -3592,7 +3610,7 @@ fn dragLeftClickTriple(
|
|||||||
} else {
|
} else {
|
||||||
sel.endPtr().* = line.end();
|
sel.endPtr().* = line.end();
|
||||||
}
|
}
|
||||||
try self.setSelection(sel);
|
try self.io.terminal.screen.select(sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dragLeftClickSingle(
|
fn dragLeftClickSingle(
|
||||||
@ -3646,7 +3664,7 @@ fn dragLeftClickSingle(
|
|||||||
else
|
else
|
||||||
cell_xpos < cell_xboundary;
|
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,
|
||||||
drag_pin,
|
drag_pin,
|
||||||
SurfaceMouse.isRectangleSelectState(self.mouse.mods),
|
SurfaceMouse.isRectangleSelectState(self.mouse.mods),
|
||||||
@ -3681,7 +3699,7 @@ fn dragLeftClickSingle(
|
|||||||
break :start start;
|
break :start start;
|
||||||
};
|
};
|
||||||
|
|
||||||
try self.setSelection(terminal.Selection.init(
|
try self.io.terminal.screen.select(terminal.Selection.init(
|
||||||
start,
|
start,
|
||||||
drag_pin,
|
drag_pin,
|
||||||
SurfaceMouse.isRectangleSelectState(self.mouse.mods),
|
SurfaceMouse.isRectangleSelectState(self.mouse.mods),
|
||||||
@ -3696,7 +3714,7 @@ fn dragLeftClickSingle(
|
|||||||
// set earlier.
|
// set earlier.
|
||||||
assert(self.io.terminal.screen.selection != null);
|
assert(self.io.terminal.screen.selection != null);
|
||||||
const sel = self.io.terminal.screen.selection.?;
|
const sel = self.io.terminal.screen.selection.?;
|
||||||
try self.setSelection(terminal.Selection.init(
|
try self.io.terminal.screen.select(terminal.Selection.init(
|
||||||
sel.start(),
|
sel.start(),
|
||||||
drag_pin,
|
drag_pin,
|
||||||
sel.rectangle,
|
sel.rectangle,
|
||||||
@ -3740,7 +3758,7 @@ fn checkResetSelSwitch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Nullifying a selection can't fail.
|
// 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.
|
// Handles how whether or not the drag screen point is before the click point.
|
||||||
|
Reference in New Issue
Block a user