mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
selection: mark-word using spaces only as word separator
When the user double-clicks with ctrl pressed, we now select the word under the cursor using spaces only as word separator.
This commit is contained in:
parent
528ee9925c
commit
c62ce72778
3 changed files with 15 additions and 8 deletions
3
input.c
3
input.c
|
|
@ -408,7 +408,8 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
|||
|
||||
if (button == BTN_LEFT) {
|
||||
if (double_click)
|
||||
selection_mark_word(term, term->mouse.col, term->mouse.row, serial);
|
||||
selection_mark_word(term, term->mouse.col, term->mouse.row,
|
||||
term->kbd.ctrl, serial);
|
||||
else
|
||||
selection_start(term, term->mouse.col, term->mouse.row);
|
||||
} else {
|
||||
|
|
|
|||
16
selection.c
16
selection.c
|
|
@ -225,8 +225,11 @@ selection_cancel(struct terminal *term)
|
|||
}
|
||||
|
||||
static bool
|
||||
isword(wint_t c)
|
||||
isword(wint_t c, bool spaces_only)
|
||||
{
|
||||
if (spaces_only)
|
||||
return !iswspace(c);
|
||||
|
||||
switch (c) {
|
||||
default: return !iswspace(c);
|
||||
|
||||
|
|
@ -243,7 +246,8 @@ isword(wint_t c)
|
|||
}
|
||||
|
||||
void
|
||||
selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
|
||||
selection_mark_word(struct terminal *term, int col, int row, bool spaces_only,
|
||||
uint32_t serial)
|
||||
{
|
||||
if (!selection_enabled(term))
|
||||
return;
|
||||
|
|
@ -256,7 +260,7 @@ selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
|
|||
const struct row *r = grid_row_in_view(term->grid, start.row);
|
||||
wchar_t c = r->cells[start.col].wc;
|
||||
|
||||
if (!(c == 0 || !isword(c))) {
|
||||
if (!(c == 0 || !isword(c, spaces_only))) {
|
||||
while (true) {
|
||||
int next_col = start.col - 1;
|
||||
int next_row = start.row;
|
||||
|
|
@ -271,7 +275,7 @@ selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
|
|||
const struct row *row = grid_row_in_view(term->grid, next_row);
|
||||
|
||||
c = row->cells[next_col].wc;
|
||||
if (c == 0 || !isword(c))
|
||||
if (c == 0 || !isword(c, spaces_only))
|
||||
break;
|
||||
|
||||
start.col = next_col;
|
||||
|
|
@ -282,7 +286,7 @@ selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
|
|||
r = grid_row_in_view(term->grid, end.row);
|
||||
c = r->cells[end.col].wc;
|
||||
|
||||
if (!(c == 0 || !isword(c))) {
|
||||
if (!(c == 0 || !isword(c, spaces_only))) {
|
||||
while (true) {
|
||||
int next_col = end.col + 1;
|
||||
int next_row = end.row;
|
||||
|
|
@ -297,7 +301,7 @@ selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
|
|||
const struct row *row = grid_row_in_view(term->grid, next_row);
|
||||
|
||||
c = row->cells[next_col].wc;
|
||||
if (c == '\0' || !isword(c))
|
||||
if (c == '\0' || !isword(c, spaces_only))
|
||||
break;
|
||||
|
||||
end.col = next_col;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <wayland-client.h>
|
||||
|
||||
#include "terminal.h"
|
||||
|
|
@ -11,7 +12,8 @@ void selection_start(struct terminal *term, int col, int row);
|
|||
void selection_update(struct terminal *term, int col, int row);
|
||||
void selection_finalize(struct terminal *term, uint32_t serial);
|
||||
void selection_cancel(struct terminal *term);
|
||||
void selection_mark_word(struct terminal *term, int col, int row, uint32_t serial);
|
||||
void selection_mark_word(struct terminal *term, int col, int row,
|
||||
bool spaces_only, uint32_t serial);
|
||||
|
||||
void selection_to_clipboard(struct terminal *term, uint32_t serial);
|
||||
void selection_from_clipboard(struct terminal *term, uint32_t serial);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue