Skip to content

Commit

Permalink
Fix autoscroll not being enabled by hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseDreki committed Feb 26, 2024
1 parent bda41bb commit fb5540d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 0 additions & 2 deletions src/nativeMain/kotlin/ui/logLines/LogLineExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ suspend fun LogLinesView.processLogLine(
refresh()
}



yield()
}

Expand Down
35 changes: 24 additions & 11 deletions src/nativeMain/kotlin/ui/logLines/LogLinesPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import dogcat.Unparseable
import dogcat.state.PublicState.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.buffer
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import logger.Logger
import logger.context
Expand All @@ -24,6 +21,7 @@ class LogLinesPresenter(
private val appState: AppState,
private val input: Input,
) : HasLifecycle {

//views can come and go, when input disappears
private lateinit var view: LogLinesView

Expand All @@ -40,10 +38,23 @@ class LogLinesPresenter(
collectKeypresses()
}

scope.launch {
appState.state
.map { it.autoscroll }
.distinctUntilChanged()
.collect {
if (it) {
Logger.d("AUTOSCROLL: $it")
view.end()
}
}
}

scope.launch {
appState.state
.collect {
view.state = view.state.copy(
autoscroll = it.autoscroll,
isCursorHeld = it.isCursorHeld,
cursorReturnLocation = it.inputFilterLocation
)
Expand Down Expand Up @@ -100,43 +111,45 @@ class LogLinesPresenter(
input
.keypresses
.collect {
Logger.d("${context()} Log lines key")
when (Keymap.bindings[it]) {
Home -> {
appState.autoscroll(false)
view.state = view.state.copy(autoscroll = false)
//view.state = view.state.copy(autoscroll = false)
view.home()
}

End -> {
appState.autoscroll(true)
view.state = view.state.copy(autoscroll = true)
//view.state = view.state.copy(autoscroll = true)
view.end()
}

LineUp -> {
appState.autoscroll(false)
view.state = view.state.copy(autoscroll = false)
//view.state = view.state.copy(autoscroll = false)
view.lineUp()
}

LineDown -> {
appState.autoscroll(false)
view.state = view.state.copy(autoscroll = false)
//view.state = view.state.copy(autoscroll = false)
view.lineDown(1)
}

PageDown -> {
appState.autoscroll(false)
view.pageDown()
}

PageUp -> {
appState.autoscroll(false)
view.state = view.state.copy(autoscroll = false)
//view.state = view.state.copy(autoscroll = false)
view.pageUp()
}

else -> {}
else -> {
// Other keys are handled elsewhere
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/nativeMain/kotlin/ui/status/StatusView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class StatusView {

wrefresh(window)

//do not return if alreadey in place
if (state.isCursorHeld) {
Logger.d("STATUS VIEW -- RETURN CURSOR")
//Logger.d("STATUS VIEW -- RETURN CURSOR")
wmove(stdscr, state.cursorReturnLocation!!.second, state.cursorReturnLocation!!.first)
curs_set(1)
wrefresh(stdscr)
Expand Down

0 comments on commit fb5540d

Please sign in to comment.