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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
Briar Desktop
Commits
86051d03
Verified
Commit
86051d03
authored
1 year ago
by
Mikolai Gütschow
Committed by
Sebastian
1 year ago
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
Hide 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(
...
@@ -114,15 +114,13 @@ fun HtmlText(
val
formattedString
=
remember
(
html
)
{
val
formattedString
=
remember
(
html
)
{
buildAnnotatedString
{
buildAnnotatedString
{
var
cursorPosition
=
0
// todo: couldn't this be replaced with this.length?
fun
append
(
str
:
String
)
{
fun
appendAndUpdateCursor
(
str
:
String
)
{
this
.
append
(
str
)
append
(
str
)
cursorPosition
+=
str
.
length
lastCharWasNewline
=
str
.
last
()
==
'\n'
lastCharWasNewline
=
str
.
last
()
==
'\n'
}
}
fun
ensureNewline
()
{
fun
ensureNewline
()
{
if
(!
lastCharWasNewline
)
append
AndUpdateCursor
(
"\n"
)
if
(!
lastCharWasNewline
)
append
(
"\n"
)
}
}
fun
pushIndent
(
indent
:
TextUnit
)
{
fun
pushIndent
(
indent
:
TextUnit
)
{
...
@@ -131,37 +129,35 @@ fun HtmlText(
...
@@ -131,37 +129,35 @@ fun HtmlText(
var
combinedIndent
=
indent
var
combinedIndent
=
indent
if
(
indentStack
.
isNotEmpty
())
{
if
(
indentStack
.
isNotEmpty
())
{
val
prev
=
indentStack
.
top
()
val
prev
=
indentStack
.
top
()
if
(
prev
.
start
<
cursorPosition
)
{
if
(
prev
.
start
<
length
)
{
println
(
"pushIndent: ${prev.start}-$cursorPosition"
)
addStyle
(
addStyle
(
style
=
ParagraphStyle
(
textIndent
=
TextIndent
(
prev
.
indent
,
prev
.
indent
)),
style
=
ParagraphStyle
(
textIndent
=
TextIndent
(
prev
.
indent
,
prev
.
indent
)),
start
=
prev
.
start
,
start
=
prev
.
start
,
end
=
cursorPosition
end
=
length
)
)
// ensureNewline()
// ensureNewline()
}
}
combinedIndent
=
(
prev
.
indent
.
value
+
indent
.
value
).
sp
combinedIndent
=
(
prev
.
indent
.
value
+
indent
.
value
).
sp
}
}
indentStack
.
push
(
IndentInfo
(
combinedIndent
,
cursorPosition
))
indentStack
.
push
(
IndentInfo
(
combinedIndent
,
length
))
}
}
fun
popIndent
()
{
fun
popIndent
()
{
check
(
indentStack
.
isNotEmpty
())
{
"nothing to pop from"
}
check
(
indentStack
.
isNotEmpty
())
{
"nothing to pop from"
}
val
prev
=
indentStack
.
pop
()
val
prev
=
indentStack
.
pop
()
if
(
prev
.
start
<
cursorPosition
)
{
if
(
prev
.
start
<
length
)
{
println
(
"popIndent: ${prev.start}-$cursorPosition"
)
addStyle
(
addStyle
(
style
=
ParagraphStyle
(
textIndent
=
TextIndent
(
prev
.
indent
,
prev
.
indent
)),
style
=
ParagraphStyle
(
textIndent
=
TextIndent
(
prev
.
indent
,
prev
.
indent
)),
start
=
prev
.
start
,
start
=
prev
.
start
,
end
=
cursorPosition
end
=
length
)
)
ensureNewline
()
ensureNewline
()
}
}
if
(
indentStack
.
isNotEmpty
())
{
if
(
indentStack
.
isNotEmpty
())
{
val
next
=
indentStack
.
pop
()
val
next
=
indentStack
.
pop
()
indentStack
.
push
(
next
.
copy
(
start
=
cursorPosition
))
indentStack
.
push
(
next
.
copy
(
start
=
length
))
}
}
}
}
...
@@ -204,8 +200,8 @@ fun HtmlText(
...
@@ -204,8 +200,8 @@ fun HtmlText(
),
),
"q"
to
HtmlNode
(
"q"
to
HtmlNode
(
// todo: quotation marks should be properly localized
// todo: quotation marks should be properly localized
start
=
{
append
AndUpdateCursor
(
"\""
)
},
start
=
{
append
(
"\""
)
},
end
=
{
append
AndUpdateCursor
(
"\""
)
}
end
=
{
append
(
"\""
)
}
),
),
"a"
to
HtmlNode
(
"a"
to
HtmlNode
(
start
=
{
node
->
start
=
{
node
->
...
@@ -252,11 +248,11 @@ fun HtmlText(
...
@@ -252,11 +248,11 @@ fun HtmlText(
listNumbering
.
incrementCurrent
()
listNumbering
.
incrementCurrent
()
if
(
listType
==
UNORDERED
)
{
if
(
listType
==
UNORDERED
)
{
val
bulletType
=
listNesting
.
size
-
1
val
bulletType
=
listNesting
.
size
-
1
append
AndUpdateCursor
(
listBullets
[
bulletType
%
listBullets
.
size
])
append
(
listBullets
[
bulletType
%
listBullets
.
size
])
append
AndUpdateCursor
(
" "
)
append
(
" "
)
pushStringAnnotation
(
"bullet"
,
listNesting
.
size
.
toString
())
pushStringAnnotation
(
"bullet"
,
listNesting
.
size
.
toString
())
}
else
if
(
listType
==
ORDERED
)
{
}
else
if
(
listType
==
ORDERED
)
{
append
AndUpdateCursor
(
"${listNumbering.top()}. "
)
append
(
"${listNumbering.top()}. "
)
pushStringAnnotation
(
"bullet"
,
listNesting
.
size
.
toString
())
pushStringAnnotation
(
"bullet"
,
listNesting
.
size
.
toString
())
}
}
},
},
...
@@ -267,7 +263,7 @@ fun HtmlText(
...
@@ -267,7 +263,7 @@ fun HtmlText(
),
),
// misc
// misc
"br"
to
HtmlNode
(
start
=
{
append
AndUpdateCursor
(
"\n"
)
},
end
=
{}),
"br"
to
HtmlNode
(
start
=
{
append
(
"\n"
)
},
end
=
{}),
"p"
to
HtmlNode
(
"p"
to
HtmlNode
(
start
=
{
pushIndent
(
0
.
sp
)
},
start
=
{
pushIndent
(
0
.
sp
)
},
end
=
{
popIndent
()
}
end
=
{
popIndent
()
}
...
@@ -310,7 +306,7 @@ fun HtmlText(
...
@@ -310,7 +306,7 @@ fun HtmlText(
// remove whitespace if first character in new line
// remove whitespace if first character in new line
.
let
{
if
(
lastCharWasNewline
)
it
.
trimStart
()
else
it
}
.
let
{
if
(
lastCharWasNewline
)
it
.
trimStart
()
else
it
}
if
(
text
.
isNotBlank
())
{
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