Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Briar Desktop
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
Briar Desktop
Commits
86051d03
Verified
Commit
86051d03
authored
Aug 30, 2023
by
Mikolai Gütschow
Committed by
Sebastian
Aug 31, 2023
Browse files
Options
Downloads
Patches
Plain Diff
remove redundant cursorPosition
parent
70e8e5c0
No related branches found
No related tags found
1 merge request
!366
Add support for HTML blog posts
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/HtmlText.kt
+16
-20
16 additions, 20 deletions
...in/kotlin/org/briarproject/briar/desktop/blog/HtmlText.kt
with
16 additions
and
20 deletions
briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/HtmlText.kt
+
16
−
20
View file @
86051d03
...
...
@@ -114,15 +114,13 @@ fun HtmlText(
val
formattedString
=
remember
(
html
)
{
buildAnnotatedString
{
var
cursorPosition
=
0
// todo: couldn't this be replaced with this.length?
fun
appendAndUpdateCursor
(
str
:
String
)
{
append
(
str
)
cursorPosition
+=
str
.
length
fun
append
(
str
:
String
)
{
this
.
append
(
str
)
lastCharWasNewline
=
str
.
last
()
==
'\n'
}
fun
ensureNewline
()
{
if
(!
lastCharWasNewline
)
append
AndUpdateCursor
(
"\n"
)
if
(!
lastCharWasNewline
)
append
(
"\n"
)
}
fun
pushIndent
(
indent
:
TextUnit
)
{
...
...
@@ -131,37 +129,35 @@ fun HtmlText(
var
combinedIndent
=
indent
if
(
indentStack
.
isNotEmpty
())
{
val
prev
=
indentStack
.
top
()
if
(
prev
.
start
<
cursorPosition
)
{
println
(
"pushIndent: ${prev.start}-$cursorPosition"
)
if
(
prev
.
start
<
length
)
{
addStyle
(
style
=
ParagraphStyle
(
textIndent
=
TextIndent
(
prev
.
indent
,
prev
.
indent
)),
start
=
prev
.
start
,
end
=
cursorPosition
end
=
length
)
// ensureNewline()
}
combinedIndent
=
(
prev
.
indent
.
value
+
indent
.
value
).
sp
}
indentStack
.
push
(
IndentInfo
(
combinedIndent
,
cursorPosition
))
indentStack
.
push
(
IndentInfo
(
combinedIndent
,
length
))
}
fun
popIndent
()
{
check
(
indentStack
.
isNotEmpty
())
{
"nothing to pop from"
}
val
prev
=
indentStack
.
pop
()
if
(
prev
.
start
<
cursorPosition
)
{
println
(
"popIndent: ${prev.start}-$cursorPosition"
)
if
(
prev
.
start
<
length
)
{
addStyle
(
style
=
ParagraphStyle
(
textIndent
=
TextIndent
(
prev
.
indent
,
prev
.
indent
)),
start
=
prev
.
start
,
end
=
cursorPosition
end
=
length
)
ensureNewline
()
}
if
(
indentStack
.
isNotEmpty
())
{
val
next
=
indentStack
.
pop
()
indentStack
.
push
(
next
.
copy
(
start
=
cursorPosition
))
indentStack
.
push
(
next
.
copy
(
start
=
length
))
}
}
...
...
@@ -204,8 +200,8 @@ fun HtmlText(
),
"q"
to
HtmlNode
(
// todo: quotation marks should be properly localized
start
=
{
append
AndUpdateCursor
(
"\""
)
},
end
=
{
append
AndUpdateCursor
(
"\""
)
}
start
=
{
append
(
"\""
)
},
end
=
{
append
(
"\""
)
}
),
"a"
to
HtmlNode
(
start
=
{
node
->
...
...
@@ -252,11 +248,11 @@ fun HtmlText(
listNumbering
.
incrementCurrent
()
if
(
listType
==
UNORDERED
)
{
val
bulletType
=
listNesting
.
size
-
1
append
AndUpdateCursor
(
listBullets
[
bulletType
%
listBullets
.
size
])
append
AndUpdateCursor
(
" "
)
append
(
listBullets
[
bulletType
%
listBullets
.
size
])
append
(
" "
)
pushStringAnnotation
(
"bullet"
,
listNesting
.
size
.
toString
())
}
else
if
(
listType
==
ORDERED
)
{
append
AndUpdateCursor
(
"${listNumbering.top()}. "
)
append
(
"${listNumbering.top()}. "
)
pushStringAnnotation
(
"bullet"
,
listNesting
.
size
.
toString
())
}
},
...
...
@@ -267,7 +263,7 @@ fun HtmlText(
),
// misc
"br"
to
HtmlNode
(
start
=
{
append
AndUpdateCursor
(
"\n"
)
},
end
=
{}),
"br"
to
HtmlNode
(
start
=
{
append
(
"\n"
)
},
end
=
{}),
"p"
to
HtmlNode
(
start
=
{
pushIndent
(
0
.
sp
)
},
end
=
{
popIndent
()
}
...
...
@@ -310,7 +306,7 @@ fun HtmlText(
// remove whitespace if first character in new line
.
let
{
if
(
lastCharWasNewline
)
it
.
trimStart
()
else
it
}
if
(
text
.
isNotBlank
())
{
append
AndUpdateCursor
(
text
)
append
(
text
)
}
}
...
...
...
...
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