fix url highlighting and search function due to deprecation function from vte291-0.62

- 解决由于vte291部分函数废弃导致的url高亮和搜索问题
This commit is contained in:
yuanxing 2022-06-14 15:54:00 +08:00
parent faebc4cf04
commit b18aa9e159
3 changed files with 313 additions and 2 deletions

View File

@ -0,0 +1,129 @@
From 7ca68048c4f59019469777a5800e58d040f84a01 Mon Sep 17 00:00:00 2001
From: yuanxing <yuanxing@kylinsec.com.cn>
Date: Tue, 14 Jun 2022 11:18:05 +0800
Subject: [PATCH 1/2] fix url highlighting due to deprecation of
vte_terminal_match_add_gregex
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 解决由于vte_terminal_match_add_gregex函数废弃的url高亮问题
---
src/terminal-screen.c | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 438ecbd..6b946b3 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -45,6 +45,9 @@
#include "eggshell.h"
+#define PCRE2_CODE_UNIT_WIDTH 0
+#include <pcre2.h>
+
#define URL_MATCH_CURSOR (GDK_HAND2)
#define SKEY_MATCH_CURSOR (GDK_HAND2)
@@ -158,30 +161,30 @@ typedef struct
{
const char *pattern;
TerminalURLFlavour flavor;
- GRegexCompileFlags flags;
+ guint32 flags;
} TerminalRegexPattern;
static const TerminalRegexPattern url_regex_patterns[] =
{
- { SCHEME "//(?:" USERPASS "\\@)?" HOST PORT URLPATH, FLAVOR_AS_IS, G_REGEX_CASELESS },
- { "(?:www|ftp)" HOSTCHARS_CLASS "*\\." HOST PORT URLPATH , FLAVOR_DEFAULT_TO_HTTP, G_REGEX_CASELESS },
- { "(?:callto:|h323:|sip:)" USERCHARS_CLASS "[" USERCHARS ".]*(?:" PORT "/[a-z0-9]+)?\\@" HOST, FLAVOR_VOIP_CALL, G_REGEX_CASELESS },
- { "(?:mailto:)?" USERCHARS_CLASS "[" USERCHARS ".]*\\@" HOSTCHARS_CLASS "+\\." HOST, FLAVOR_EMAIL, G_REGEX_CASELESS },
- { "news:[[:alnum:]\\Q^_{|}~!\"#$%&'()*+,./;:=?`\\E]+", FLAVOR_AS_IS, G_REGEX_CASELESS },
+ { SCHEME "//(?:" USERPASS "\\@)?" HOST PORT URLPATH, FLAVOR_AS_IS, PCRE2_CASELESS },
+ { "(?:www|ftp)" HOSTCHARS_CLASS "*\\." HOST PORT URLPATH , FLAVOR_DEFAULT_TO_HTTP, PCRE2_CASELESS },
+ { "(?:callto:|h323:|sip:)" USERCHARS_CLASS "[" USERCHARS ".]*(?:" PORT "/[a-z0-9]+)?\\@" HOST, FLAVOR_VOIP_CALL, PCRE2_CASELESS },
+ { "(?:mailto:)?" USERCHARS_CLASS "[" USERCHARS ".]*\\@" HOSTCHARS_CLASS "+\\." HOST, FLAVOR_EMAIL, PCRE2_CASELESS },
+ { "news:[[:alnum:]\\Q^_{|}~!\"#$%&'()*+,./;:=?`\\E]+", FLAVOR_AS_IS, PCRE2_CASELESS },
};
-static GRegex **url_regexes;
+static VteRegex **url_regexes;
static TerminalURLFlavour *url_regex_flavors;
static guint n_url_regexes;
#ifdef ENABLE_SKEY
static const TerminalRegexPattern skey_regex_patterns[] =
{
- { "s/key [[:digit:]]* [-[:alnum:]]*", FLAVOR_AS_IS },
- { "otp-[a-z0-9]* [[:digit:]]* [-[:alnum:]]*", FLAVOR_AS_IS },
+ { "s/key [[:digit:]]* [-[:alnum:]]*", FLAVOR_AS_IS, 0 },
+ { "otp-[a-z0-9]* [[:digit:]]* [-[:alnum:]]*", FLAVOR_AS_IS, 0 },
};
-static GRegex **skey_regexes;
+static VteRegex **skey_regexes;
static guint n_skey_regexes;
static void terminal_screen_skey_match_remove (TerminalScreen *screen);
@@ -357,7 +360,7 @@ terminal_screen_init (TerminalScreen *screen)
tag_data = g_slice_new (TagData);
tag_data->flavor = url_regex_flavors[i];
- tag_data->tag = vte_terminal_match_add_gregex (terminal, url_regexes[i], 0);
+ tag_data->tag = vte_terminal_match_add_regex (terminal, url_regexes[i], 0);
vte_terminal_match_set_cursor_type (terminal, tag_data->tag, URL_MATCH_CURSOR);
priv->match_tags = g_slist_prepend (priv->match_tags, tag_data);
@@ -583,16 +586,15 @@ terminal_screen_class_init (TerminalScreenClass *klass)
/* Precompile the regexes */
n_url_regexes = G_N_ELEMENTS (url_regex_patterns);
- url_regexes = g_new0 (GRegex*, n_url_regexes);
+ url_regexes = g_new0 (VteRegex*, n_url_regexes);
url_regex_flavors = g_new0 (TerminalURLFlavour, n_url_regexes);
for (i = 0; i < n_url_regexes; ++i)
{
GError *error = NULL;
- url_regexes[i] = g_regex_new (url_regex_patterns[i].pattern,
- url_regex_patterns[i].flags | G_REGEX_OPTIMIZE | G_REGEX_MULTILINE,
- 0, &error);
+ url_regexes[i] = vte_regex_new_for_match(url_regex_patterns[i].pattern, -1,
+ url_regex_patterns[i].flags | PCRE2_MULTILINE, &error);
if (error)
{
g_message ("%s", error->message);
@@ -604,15 +606,14 @@ terminal_screen_class_init (TerminalScreenClass *klass)
#ifdef ENABLE_SKEY
n_skey_regexes = G_N_ELEMENTS (skey_regex_patterns);
- skey_regexes = g_new0 (GRegex*, n_skey_regexes);
+ skey_regexes = g_new0 (VteRegex*, n_skey_regexes);
for (i = 0; i < n_skey_regexes; ++i)
{
GError *error = NULL;
- skey_regexes[i] = g_regex_new (skey_regex_patterns[i].pattern,
- G_REGEX_OPTIMIZE | G_REGEX_MULTILINE,
- 0, &error);
+ skey_regexes[i] = vte_regex_new_for_match(skey_regex_patterns[i].pattern, -1,
+ PCRE2_MULTILINE, &error);
if (error)
{
g_message ("%s", error->message);
@@ -1027,7 +1028,7 @@ terminal_screen_profile_notify_cb (TerminalProfile *profile,
tag_data = g_slice_new (TagData);
tag_data->flavor = FLAVOR_SKEY;
- tag_data->tag = vte_terminal_match_add_gregex (vte_terminal, skey_regexes[i], 0);
+ tag_data->tag = vte_terminal_match_add_regex (vte_terminal, skey_regexes[i], 0);
vte_terminal_match_set_cursor_type (vte_terminal, tag_data->tag, SKEY_MATCH_CURSOR);
priv->match_tags = g_slist_prepend (priv->match_tags, tag_data);
--
2.33.0

View File

@ -0,0 +1,174 @@
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

View File

@ -16,9 +16,9 @@ Summary: Terminal emulator for MATE
Name: mate-terminal
Version: %{branch}.1
%if 0%{?rel_build}
Release: 2%{?dist}
Release: 4
%else
Release: 0.8%{?git_rel}%{?dist}
Release: 0.8%{?git_rel}
%endif
License: GPLv3+
URL: http://mate-desktop.org
@ -34,6 +34,8 @@ Patch1: mate-terminal_better_defaults-1.19.0.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=1781564
# https://github.com/mate-desktop/mate-terminal/pull/316
Patch2: mate-terminal_0001-Avoid-NULL-pointer-dereference-in-terminal_screen_ch.patch
Patch3: 0001-fix-url-highlighting-due-to-deprecation-of-vte_termi.patch
Patch4: 0002-fix-searching-in-terminal-window.patch
BuildRequires: dconf-devel
BuildRequires: desktop-file-utils
@ -42,11 +44,14 @@ BuildRequires: gtk3-devel
BuildRequires: libSM-devel
BuildRequires: mate-common
BuildRequires: vte291-devel
BuildRequires: pcre2-devel
# needed to get a gsettings schema, rhbz #908105
Requires: mate-desktop-libs
Requires: gsettings-desktop-schemas
Requires: pcre2
%description
Mate-terminal is a terminal emulator for MATE. It supports translucent
backgrounds, opening multiple terminals in a single window (tabs) and
@ -95,6 +100,9 @@ desktop-file-install \
%changelog
* Tue Jun 14 2022 yuanxing <yuanxing@kylinsec.com.cn> - 1.22.1-4
- fix url highlighting and search function problem due to deprecation function from vte291-0.62
* Sat Dec 14 2019 Wolfgang Ulbrich <fedora@raveit.de> - 1.22.1-2
- use https://github.com/mate-desktop/mate-terminal/pull/316
- fixing rhbz (#1781564)