175 lines
5.3 KiB
Diff
175 lines
5.3 KiB
Diff
From a5ad3996edde350b079a11813c69d09f5c90cb09 Mon Sep 17 00:00:00 2001
|
|
From: yuanxing <yuanxing@kylinsec.com.cn>
|
|
Date: Tue, 14 Jun 2022 11:37:13 +0800
|
|
Subject: [PATCH 2/2] fix searching in terminal window
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
- 解决终端无法搜索问题
|
|
|
|
fix:#56423
|
|
---
|
|
src/terminal-screen.c | 2 +-
|
|
src/terminal-search-dialog.c | 26 +++++++++++++++-----------
|
|
src/terminal-search-dialog.h | 3 ++-
|
|
src/terminal-window.c | 6 +++---
|
|
4 files changed, 21 insertions(+), 16 deletions(-)
|
|
|
|
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
|
|
index 6b946b3..65b0e30 100644
|
|
--- a/src/terminal-screen.c
|
|
+++ b/src/terminal-screen.c
|
|
@@ -613,7 +613,7 @@ terminal_screen_class_init (TerminalScreenClass *klass)
|
|
GError *error = NULL;
|
|
|
|
skey_regexes[i] = vte_regex_new_for_match(skey_regex_patterns[i].pattern, -1,
|
|
- PCRE2_MULTILINE, &error);
|
|
+ PCRE2_MULTILINE | PCRE2_UTF | PCRE2_NO_UTF_CHECK, &error);
|
|
if (error)
|
|
{
|
|
g_message ("%s", error->message);
|
|
diff --git a/src/terminal-search-dialog.c b/src/terminal-search-dialog.c
|
|
index 7ff80e8..fb7a494 100644
|
|
--- a/src/terminal-search-dialog.c
|
|
+++ b/src/terminal-search-dialog.c
|
|
@@ -25,6 +25,9 @@
|
|
#include "terminal-search-dialog.h"
|
|
#include "terminal-util.h"
|
|
|
|
+#define PCRE2_CODE_UNIT_WIDTH 0
|
|
+#include <pcre2.h>
|
|
+
|
|
#define HISTORY_MIN_ITEM_LEN 3
|
|
#define HISTORY_LENGTH 10
|
|
|
|
@@ -60,8 +63,8 @@ typedef struct _TerminalSearchDialogPrivate
|
|
GtkEntryCompletion *completion;
|
|
|
|
/* Cached regex */
|
|
- GRegex *regex;
|
|
- GRegexCompileFlags regex_compile_flags;
|
|
+ VteRegex *regex;
|
|
+ guint32 regex_compile_flags;
|
|
} TerminalSearchDialogPrivate;
|
|
|
|
|
|
@@ -153,7 +156,7 @@ terminal_search_dialog_private_destroy (TerminalSearchDialogPrivate *priv)
|
|
{
|
|
|
|
if (priv->regex)
|
|
- g_regex_unref (priv->regex);
|
|
+ vte_regex_unref (priv->regex);
|
|
|
|
g_object_unref (priv->store);
|
|
g_object_unref (priv->completion);
|
|
@@ -171,7 +174,7 @@ update_sensitivity (void *unused, GtkWidget *dialog)
|
|
|
|
if (priv->regex)
|
|
{
|
|
- g_regex_unref (priv->regex);
|
|
+ vte_regex_unref (priv->regex);
|
|
priv->regex = NULL;
|
|
}
|
|
|
|
@@ -336,11 +339,11 @@ terminal_search_dialog_get_search_flags (GtkWidget *dialog)
|
|
return flags;
|
|
}
|
|
|
|
-GRegex *
|
|
+VteRegex *
|
|
terminal_search_dialog_get_regex (GtkWidget *dialog)
|
|
{
|
|
TerminalSearchDialogPrivate *priv;
|
|
- GRegexCompileFlags compile_flags;
|
|
+ guint32 compile_flags;
|
|
const char *text, *pattern;
|
|
|
|
g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
|
|
@@ -350,13 +353,13 @@ terminal_search_dialog_get_regex (GtkWidget *dialog)
|
|
|
|
pattern = text = terminal_search_dialog_get_search_text (dialog);
|
|
|
|
- compile_flags = G_REGEX_OPTIMIZE;
|
|
+ compile_flags = PCRE2_MULTILINE | PCRE2_UTF | PCRE2_NO_UTF_CHECK;
|
|
|
|
if (!GET_FLAG (match_case_checkbutton))
|
|
- compile_flags |= G_REGEX_CASELESS;
|
|
+ compile_flags |= PCRE2_CASELESS;
|
|
|
|
if (GET_FLAG (regex_checkbutton))
|
|
- compile_flags |= G_REGEX_MULTILINE;
|
|
+ compile_flags |= PCRE2_UCP;
|
|
else
|
|
pattern = g_regex_escape_string (text, -1);
|
|
|
|
@@ -372,10 +375,11 @@ terminal_search_dialog_get_regex (GtkWidget *dialog)
|
|
{
|
|
priv->regex_compile_flags = compile_flags;
|
|
if (priv->regex)
|
|
- g_regex_unref (priv->regex);
|
|
+ vte_regex_unref (priv->regex);
|
|
|
|
/* TODO Error handling */
|
|
- priv->regex = g_regex_new (pattern, compile_flags, 0, NULL);
|
|
+ priv->regex = vte_regex_new_for_search(pattern, -1,
|
|
+ compile_flags, NULL);
|
|
}
|
|
|
|
if (pattern != text)
|
|
diff --git a/src/terminal-search-dialog.h b/src/terminal-search-dialog.h
|
|
index 593290a..cc31f37 100644
|
|
--- a/src/terminal-search-dialog.h
|
|
+++ b/src/terminal-search-dialog.h
|
|
@@ -22,6 +22,7 @@
|
|
#define TERMINAL_SEARCH_DIALOG_H
|
|
|
|
#include <gtk/gtk.h>
|
|
+#include <vte/vte.h>
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
@@ -43,7 +44,7 @@ const gchar *terminal_search_dialog_get_search_text (GtkWidget *dialog);
|
|
|
|
TerminalSearchFlags
|
|
terminal_search_dialog_get_search_flags(GtkWidget *dialog);
|
|
-GRegex *terminal_search_dialog_get_regex (GtkWidget *dialog);
|
|
+VteRegex *terminal_search_dialog_get_regex (GtkWidget *dialog);
|
|
|
|
G_END_DECLS
|
|
|
|
diff --git a/src/terminal-window.c b/src/terminal-window.c
|
|
index a6784bc..d172ecc 100644
|
|
--- a/src/terminal-window.c
|
|
+++ b/src/terminal-window.c
|
|
@@ -3993,7 +3993,7 @@ search_find_response_callback (GtkWidget *dialog,
|
|
TerminalWindow *window = TERMINAL_WINDOW (user_data);
|
|
TerminalWindowPrivate *priv = window->priv;
|
|
TerminalSearchFlags flags;
|
|
- GRegex *regex;
|
|
+ VteRegex *regex;
|
|
|
|
if (response != GTK_RESPONSE_ACCEPT)
|
|
return;
|
|
@@ -4006,7 +4006,7 @@ search_find_response_callback (GtkWidget *dialog,
|
|
|
|
flags = terminal_search_dialog_get_search_flags (dialog);
|
|
|
|
- vte_terminal_search_set_gregex (VTE_TERMINAL (priv->active_screen), regex, 0);
|
|
+ vte_terminal_search_set_regex (VTE_TERMINAL (priv->active_screen), regex, 0);
|
|
vte_terminal_search_set_wrap_around (VTE_TERMINAL (priv->active_screen),
|
|
(flags & TERMINAL_SEARCH_FLAG_WRAP_AROUND));
|
|
|
|
@@ -4077,7 +4077,7 @@ search_clear_highlight_callback (GtkAction *action,
|
|
if (G_UNLIKELY (!window->priv->active_screen))
|
|
return;
|
|
|
|
- vte_terminal_search_set_gregex (VTE_TERMINAL (window->priv->active_screen), NULL, 0);
|
|
+ vte_terminal_search_set_regex (VTE_TERMINAL (window->priv->active_screen), NULL, 0);
|
|
}
|
|
|
|
static void
|
|
--
|
|
2.33.0
|
|
|