Skip to content

Commit

Permalink
Update line on _buffer_line_data_changed
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoran committed Dec 7, 2024
1 parent e0e2b3f commit 963f7a4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ class Buffer @WorkerThread constructor(
}
}

@WorkerThread @Synchronized fun replaceLine(line: Line) {
if (isOpen) line.ensureSpannable()

synchronized(this) {
lines.replaceLine(line)
}
}

@WorkerThread fun addLineBottom(line: Line) {
if (isOpen) line.ensureSpannable()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,16 @@ object BufferList {
}
}

add("_buffer_line_data_changed") { obj, _ ->
obj.forEach { entry ->
val spec = LineSpec(entry)
findByPointer(spec.bufferPointer)?.let { buffer ->
buffer.replaceLine(spec.toLine())
buffer.onLinesListed()
}
}
}

return handlers
}

Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Lines.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.ubergeek42.WeechatAndroid.utils.invalidatableLazy
import com.ubergeek42.weechat.Color
import java.util.*
import kotlin.properties.Delegates.observable
import kotlin.collections.ArrayDeque;

// this class is supposed to be synchronized by Buffer
class Lines {
Expand Down Expand Up @@ -97,6 +98,16 @@ class Lines {
}
}

fun replaceLine(line: Line) {
val index = unfiltered.indexOfFirst { l -> l.pointer == line.pointer }
if (index == -1) return
filtered.clear();
unfiltered[index] = line
for (l in unfiltered) {
if (l.isVisible) filtered.add(l)
}
}

fun addLast(line: Line) {
if (shouldAddSquiggleOnNewLine) {
shouldAddSquiggleOnNewLine = false
Expand Down Expand Up @@ -164,7 +175,7 @@ class Lines {

////////////////////////////////////////////////////////////////////////////////////////////////

val descendingFilteredIterator: Iterator<Line> get() = filtered.descendingIterator()
val descendingFilteredIterator: Iterator<Line> get() = filtered.asReversed().iterator()


fun invalidateSpannables() {
Expand Down Expand Up @@ -197,7 +208,7 @@ class Lines {
fun rememberCurrentSkipsOffset() {
skipFilteredOffset = skipFiltered
skipUnfilteredOffset = skipUnfiltered
if (unfiltered.size > 0) _lastSeenLine = unfiltered.last.pointer
if (unfiltered.size > 0) _lastSeenLine = unfiltered.last().pointer
}

////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -216,7 +227,7 @@ class Lines {
var indexFiltered = 0
var indexUnfiltered = 0

unfiltered.descendingIterator().forEach { line ->
unfiltered.asReversed().iterator().forEach { line ->
if (line.pointer == _lastSeenLine) {
skipFiltered = indexFiltered
skipUnfiltered = indexUnfiltered
Expand Down

0 comments on commit 963f7a4

Please sign in to comment.