Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mesonium
gajim
Commits
5462da5a
Commit
5462da5a
authored
2 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
fix: Styling: Process URIs when using /me command
Fixes #10988
parent
78c6711a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gajim/common/styling.py
+15
-0
15 additions, 0 deletions
gajim/common/styling.py
gajim/gtk/conversation/plain_widget.py
+26
-12
26 additions, 12 deletions
gajim/gtk/conversation/plain_widget.py
with
41 additions
and
12 deletions
gajim/common/styling.py
+
15
−
0
View file @
5462da5a
...
...
@@ -219,6 +219,21 @@ def process(text: Union[str, bytes], level: int = 0) -> ParsingResult:
return
ParsingResult
(
text
,
blocks
)
def
process_uris
(
text
:
Union
[
str
,
bytes
])
->
list
[
BaseUri
]:
if
isinstance
(
text
,
bytes
):
text
=
text
.
decode
()
uris
:
list
[
BaseUri
]
=
[]
offset
=
0
offset_bytes
=
0
for
line
in
text
.
splitlines
(
keepends
=
True
):
uris
+=
_parse_uris
(
line
,
offset
,
offset_bytes
)
offset
+=
len
(
line
)
offset_bytes
+=
len
(
line
.
encode
())
return
uris
def
_parse_blocks
(
text
:
str
,
level
:
int
)
->
list
[
Block
]:
blocks
:
list
[
Block
]
=
[]
text_len
=
len
(
text
)
...
...
This diff is collapsed.
Click to expand it.
gajim/gtk/conversation/plain_widget.py
+
26
−
12
View file @
5462da5a
...
...
@@ -31,7 +31,9 @@
from
gajim.common.helpers
import
open_uri
from
gajim.common.helpers
import
parse_uri
from
gajim.common.structs
import
URI
from
gajim.common.styling
import
BaseUri
from
gajim.common.styling
import
PlainBlock
from
gajim.common.styling
import
process_uris
from
..menus
import
get_conv_action_context_menu
from
..menus
import
get_conv_uri_context_menu
...
...
@@ -70,9 +72,7 @@ def add_content(self, block: PlainBlock) -> None:
self
.
_text_widget
.
print_text_with_styling
(
block
)
def
add_action_phrase
(
self
,
text
:
str
,
nickname
:
str
)
->
None
:
text
=
text
.
replace
(
'
/me
'
,
f
'
*
{
nickname
}
'
,
1
)
text
=
GLib
.
markup_escape_text
(
text
)
self
.
_text_widget
.
add_action_phrase
(
text
)
self
.
_text_widget
.
add_action_phrase
(
text
,
nickname
)
class
MessageLabel
(
Gtk
.
Label
):
...
...
@@ -106,16 +106,19 @@ def _on_populate_popup(self, label: Gtk.Label, menu: Gtk.Menu) -> None:
menu
.
prepend
(
action_menu_item
)
menu
.
show_all
()
def
print_text_with_styling
(
self
,
block
:
PlainBlock
)
->
None
:
text
=
''
after
=
GLib
.
markup_escape_text
(
block
.
text
.
strip
())
for
uri
in
block
.
uris
:
def
_build_link_markup
(
self
,
text
:
str
,
uris
:
list
[
BaseUri
]
)
->
str
:
markup_
text
=
''
after
=
GLib
.
markup_escape_text
(
text
.
strip
())
for
uri
in
uris
:
uri_escaped
=
GLib
.
markup_escape_text
(
uri
.
text
)
before
,
_
,
after
=
after
.
partition
(
uri_escaped
)
text
+=
before
text
+=
uri
.
get_markup_string
()
text
+=
after
markup_text
+=
before
markup_text
+=
uri
.
get_markup_string
()
markup_text
+=
after
return
markup_text
def
print_text_with_styling
(
self
,
block
:
PlainBlock
)
->
None
:
text
=
self
.
_build_link_markup
(
block
.
text
,
block
.
uris
)
self
.
set_markup
(
text
)
if
len
(
self
.
get_text
())
>
10000
:
...
...
@@ -124,7 +127,10 @@ def print_text_with_styling(self, block: PlainBlock) -> None:
self
.
set_attributes
(
make_pango_attributes
(
block
))
def
add_action_phrase
(
self
,
text
:
str
)
->
None
:
def
add_action_phrase
(
self
,
text
:
str
,
nickname
:
str
)
->
None
:
text
=
text
.
replace
(
'
/me
'
,
f
'
*
{
nickname
}
'
,
1
)
uris
=
process_uris
(
text
)
text
=
self
.
_build_link_markup
(
text
,
uris
)
self
.
set_markup
(
f
'
<i>
{
text
}
</i>
'
)
def
_on_activate_link
(
self
,
_label
:
Gtk
.
Label
,
uri
:
str
)
->
int
:
...
...
@@ -274,10 +280,18 @@ def replace_emoji(self,
buffer_
.
delete_mark
(
start_mark
)
buffer_
.
delete_mark
(
end_mark
)
def
add_action_phrase
(
self
,
text
:
str
)
->
None
:
def
add_action_phrase
(
self
,
text
:
str
,
nickname
:
str
)
->
None
:
text
=
text
.
replace
(
'
/me
'
,
f
'
*
{
nickname
}
'
,
1
)
buffer_
=
self
.
get_buffer
()
buffer_
.
insert
(
buffer_
.
get_start_iter
(),
text
.
strip
())
uris
=
process_uris
(
text
)
for
uri
in
uris
:
start_iter
=
buffer_
.
get_iter_at_offset
(
uri
.
start
)
end_iter
=
buffer_
.
get_iter_at_offset
(
uri
.
end
)
buffer_
.
apply_tag_by_name
(
uri
.
name
,
start_iter
,
end_iter
)
start_iter
=
buffer_
.
get_start_iter
()
end_iter
=
buffer_
.
get_end_iter
()
buffer_
.
apply_tag_by_name
(
'
emphasis
'
,
start_iter
,
end_iter
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment