Skip to content

Commit 2154fa4

Browse files
authored
ADFA-3122 | Fix editor viewport and buffer persistence on configuration change (#1066)
* fix(editor): preserve scroll position and file timestamps on configuration change Ensure cursor visibility after layout changes and update file timestamps after saving. * fix: Make fileTimestamps thread-safe
1 parent 0681d66 commit 2154fa4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

app/src/main/java/com/itsaky/androidide/activities/editor/EditorHandlerActivity.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.itsaky.androidide.activities.editor
1919

2020
import android.content.Intent
21+
import android.content.res.Configuration
2122
import android.os.Bundle
2223
import android.text.TextUtils
2324
import android.util.Log
@@ -26,6 +27,7 @@ import android.view.ViewGroup.LayoutParams
2627
import androidx.collection.MutableIntObjectMap
2728
import androidx.core.content.res.ResourcesCompat
2829
import androidx.core.view.GravityCompat
30+
import androidx.core.view.doOnNextLayout
2931
import androidx.lifecycle.lifecycleScope
3032
import com.blankj.utilcode.util.ImageUtils
3133
import com.google.android.material.tabs.TabLayout
@@ -79,6 +81,7 @@ import org.adfa.constants.CONTENT_KEY
7981
import org.greenrobot.eventbus.Subscribe
8082
import org.greenrobot.eventbus.ThreadMode
8183
import java.io.File
84+
import java.util.concurrent.ConcurrentHashMap
8285
import java.util.concurrent.CopyOnWriteArrayList
8386
import java.util.concurrent.atomic.AtomicBoolean
8487
import java.util.function.Consumer
@@ -100,7 +103,7 @@ open class EditorHandlerActivity :
100103

101104
protected val isOpenedFilesSaved = AtomicBoolean(false)
102105

103-
private val fileTimestamps = mutableMapOf<String, Long>()
106+
private val fileTimestamps = ConcurrentHashMap<String, Long>()
104107

105108
private val pluginTabIndices = mutableMapOf<String, Int>()
106109
private val tabIndexToPluginId = mutableMapOf<Int, String>()
@@ -704,6 +707,16 @@ open class EditorHandlerActivity :
704707
}
705708
}
706709

710+
override fun onConfigurationChanged(newConfig: Configuration) {
711+
super.onConfigurationChanged(newConfig)
712+
713+
getCurrentEditor()?.editor?.apply {
714+
doOnNextLayout {
715+
cursor?.let { c -> ensurePositionVisible(c.leftLine, c.leftColumn, true) }
716+
}
717+
}
718+
}
719+
707720
private suspend fun saveResultInternal(
708721
index: Int,
709722
result: SaveResult,
@@ -723,6 +736,10 @@ open class EditorHandlerActivity :
723736
return false
724737
}
725738

739+
frag.file?.let { savedFile ->
740+
fileTimestamps[savedFile.absolutePath] = savedFile.lastModified()
741+
}
742+
726743
val isGradle = fileName.endsWith(".gradle") || fileName.endsWith(".gradle.kts")
727744
val isXml: Boolean = fileName.endsWith(".xml")
728745
if (!result.gradleSaved) {

0 commit comments

Comments
 (0)