Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
3898b7aa
Commit
3898b7aa
authored
Dec 20, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix InlineHighlighter to use the same regex as the web app.
parent
2f9014bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
23 deletions
+39
-23
InlineHightlighter.java
...chat/rocket/android/widget/helper/InlineHightlighter.java
+39
-23
No files found.
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/helper/InlineHightlighter.java
View file @
3898b7aa
...
...
@@ -13,6 +13,8 @@ import android.text.style.StyleSpan;
import
android.text.style.TypefaceSpan
;
import
android.widget.TextView
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
chat.rocket.android.widget.R
;
public
class
InlineHightlighter
{
...
...
@@ -39,31 +41,45 @@ public class InlineHightlighter {
}
private
static
CharSequence
highlightInner
(
final
Context
context
,
final
CharSequence
text
)
{
final
SpannableString
s
=
new
SpannableString
(
text
);
final
SpannableString
inputText
=
new
SpannableString
(
text
);
final
int
length
=
text
.
length
();
int
highlightStart
=
length
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
char
chr
=
text
.
charAt
(
i
);
if
(
chr
==
'`'
)
{
if
(
i
>
highlightStart
)
{
final
int
highlightEnd
=
i
;
if
(
highlightStart
+
1
<
highlightEnd
)
{
s
.
setSpan
(
createTransparentSpan
(),
highlightStart
,
highlightStart
+
1
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
for
(
CharacterStyle
span
:
createCharStyles
(
context
))
{
s
.
setSpan
(
span
,
highlightStart
+
1
,
highlightEnd
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
s
.
setSpan
(
createTransparentSpan
(),
highlightEnd
,
highlightEnd
+
1
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
highlightStart
=
length
;
}
else
{
highlightStart
=
i
;
}
}
Pattern
highlightPattern
=
Pattern
.
compile
(
"(^|>|[ >_*~])\\`([^`\\r\\n]+)\\`([<_*~]|\\B|\\b|$)"
,
Pattern
.
MULTILINE
);
Matcher
matcher
=
highlightPattern
.
matcher
(
inputText
);
while
(
matcher
.
find
())
{
setSpan
(
inputText
,
context
,
matcher
.
start
()
+
matcher
.
group
(
1
).
length
(),
matcher
.
end
()
-
matcher
.
group
(
3
).
length
(),
1
,
1
);
}
return
inputText
;
}
private
static
void
setSpan
(
SpannableString
inputText
,
Context
context
,
int
start
,
int
end
,
int
markStartLen
,
int
markEndLen
)
{
if
(
markStartLen
>
0
)
{
inputText
.
setSpan
(
createTransparentSpan
(),
start
,
start
+
markStartLen
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
return
s
;
CharacterStyle
[]
spans
=
inputText
.
getSpans
(
start
+
markStartLen
,
end
-
markEndLen
,
CharacterStyle
.
class
);
for
(
CharacterStyle
span
:
spans
)
{
inputText
.
removeSpan
(
span
);
}
for
(
CharacterStyle
span
:
createCharStyles
(
context
))
{
inputText
.
setSpan
(
span
,
start
+
markStartLen
,
end
-
markEndLen
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
if
(
markEndLen
>
0
)
{
inputText
.
setSpan
(
createTransparentSpan
(),
end
-
markEndLen
,
end
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment