Skip to content

Commit 9146d44

Browse files
committed
Make CapturePreferences only keep track of changes
Before `CapturePreferences` would override `LocalPreferences` and halt any changes upstream until `apply` was called, now it will let those changes slip through so we get immediate feedback on changes made in the preferences screen.
1 parent 76b9bae commit 9146d44

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

app/src/processing/app/ui/PDEPreferences.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ private val LocalModifiablePreferences =
441441
compositionLocalOf { ModifiablePreference(null, false, { }, {}) }
442442

443443
/**
444-
* Composable function that provides a modifiable copy of the current preferences.
444+
* Composable function that captures an initial copy of the current preferences.
445445
* This allows for temporary changes to preferences that can be reset or applied later.
446446
*
447447
* @param content The composable content that will have access to the modifiable preferences.
@@ -498,13 +498,13 @@ private fun CapturePreferences(content: @Composable () -> Unit) {
498498
}
499499

500500
val apply = {
501-
modified.entries.forEach { (key, value) ->
502-
prefs.setProperty(key as String, (value ?: "") as String)
501+
prefs.entries.forEach { (key, value) ->
502+
modified.setProperty(key as String, (value ?: "") as String)
503503
}
504504
}
505505
val reset = {
506506
modified.entries.forEach { (key, value) ->
507-
modified.setProperty(key as String, prefs[key] ?: "")
507+
prefs.setProperty(key as String, modified[key] ?: "")
508508
}
509509
}
510510
val state = ModifiablePreference(
@@ -515,7 +515,6 @@ private fun CapturePreferences(content: @Composable () -> Unit) {
515515
)
516516

517517
CompositionLocalProvider(
518-
LocalPreferences provides modified,
519518
LocalModifiablePreferences provides state
520519
) {
521520
content()

0 commit comments

Comments
 (0)