mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-21 05:33:45 -04: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 (button == BTN_LEFT) {
|
||||||
if (double_click)
|
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
|
else
|
||||||
selection_start(term, term->mouse.col, term->mouse.row);
|
selection_start(term, term->mouse.col, term->mouse.row);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
16
selection.c
16
selection.c
|
|
@ -225,8 +225,11 @@ selection_cancel(struct terminal *term)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
isword(wint_t c)
|
isword(wint_t c, bool spaces_only)
|
||||||
{
|
{
|
||||||
|
if (spaces_only)
|
||||||
|
return !iswspace(c);
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
default: return !iswspace(c);
|
default: return !iswspace(c);
|
||||||
|
|
||||||
|
|
@ -243,7 +246,8 @@ isword(wint_t c)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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))
|
if (!selection_enabled(term))
|
||||||
return;
|
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);
|
const struct row *r = grid_row_in_view(term->grid, start.row);
|
||||||
wchar_t c = r->cells[start.col].wc;
|
wchar_t c = r->cells[start.col].wc;
|
||||||
|
|
||||||
if (!(c == 0 || !isword(c))) {
|
if (!(c == 0 || !isword(c, spaces_only))) {
|
||||||
while (true) {
|
while (true) {
|
||||||
int next_col = start.col - 1;
|
int next_col = start.col - 1;
|
||||||
int next_row = start.row;
|
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);
|
const struct row *row = grid_row_in_view(term->grid, next_row);
|
||||||
|
|
||||||
c = row->cells[next_col].wc;
|
c = row->cells[next_col].wc;
|
||||||
if (c == 0 || !isword(c))
|
if (c == 0 || !isword(c, spaces_only))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
start.col = next_col;
|
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);
|
r = grid_row_in_view(term->grid, end.row);
|
||||||
c = r->cells[end.col].wc;
|
c = r->cells[end.col].wc;
|
||||||
|
|
||||||
if (!(c == 0 || !isword(c))) {
|
if (!(c == 0 || !isword(c, spaces_only))) {
|
||||||
while (true) {
|
while (true) {
|
||||||
int next_col = end.col + 1;
|
int next_col = end.col + 1;
|
||||||
int next_row = end.row;
|
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);
|
const struct row *row = grid_row_in_view(term->grid, next_row);
|
||||||
|
|
||||||
c = row->cells[next_col].wc;
|
c = row->cells[next_col].wc;
|
||||||
if (c == '\0' || !isword(c))
|
if (c == '\0' || !isword(c, spaces_only))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
end.col = next_col;
|
end.col = next_col;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
|
||||||
#include "terminal.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_update(struct terminal *term, int col, int row);
|
||||||
void selection_finalize(struct terminal *term, uint32_t serial);
|
void selection_finalize(struct terminal *term, uint32_t serial);
|
||||||
void selection_cancel(struct terminal *term);
|
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_to_clipboard(struct terminal *term, uint32_t serial);
|
||||||
void selection_from_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