Skip to content

Commit 1af2eb7

Browse files
authored
Make CapturePreferences only keep track of changes (#1383)
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 aaa3f75 commit 1af2eb7

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
@@ -443,7 +443,7 @@ private val LocalModifiablePreferences =
443443
compositionLocalOf { ModifiablePreference(null, false, { }, {}) }
444444

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

502502
val apply = {
503-
modified.entries.forEach { (key, value) ->
504-
prefs.setProperty(key as String, (value ?: "") as String)
503+
prefs.entries.forEach { (key, value) ->
504+
modified.setProperty(key as String, (value ?: "") as String)
505505
}
506506
}
507507
val reset = {
508508
modified.entries.forEach { (key, value) ->
509-
modified.setProperty(key as String, prefs[key] ?: "")
509+
prefs.setProperty(key as String, modified[key] ?: "")
510510
}
511511
}
512512
val state = ModifiablePreference(
@@ -517,7 +517,6 @@ private fun CapturePreferences(content: @Composable () -> Unit) {
517517
)
518518

519519
CompositionLocalProvider(
520-
LocalPreferences provides modified,
521520
LocalModifiablePreferences provides state
522521
) {
523522
content()

0 commit comments

Comments
 (0)