mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix(editor): content modification status is not updated when editor.setText() is used (fixes #878)
This commit is contained in:
Binary file not shown.
@@ -251,9 +251,6 @@ open class EditorHandlerActivity : ProjectHandlerActivity(), IEditorHandler {
|
||||
log.info("Opening file at index:", position, "file: ", file)
|
||||
|
||||
val editor = CodeEditorView(this, file, selection!!)
|
||||
editor.editor.subscribeEvent(ContentChangeEvent::class.java) { event, _ ->
|
||||
onEditorContentChanged(event)
|
||||
}
|
||||
editor.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
|
||||
|
||||
binding.editorContainer.addView(editor)
|
||||
@@ -365,11 +362,9 @@ open class EditorHandlerActivity : ProjectHandlerActivity(), IEditorHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private fun onEditorContentChanged(event: ContentChangeEvent) {
|
||||
if (event.action != ContentChangeEvent.ACTION_SET_NEW_TEXT) {
|
||||
viewModel.setFilesModified(true)
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
private fun onEditorContentChanged() {
|
||||
viewModel.setFilesModified(true)
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
override fun areFilesModified(): Boolean {
|
||||
@@ -542,6 +537,9 @@ open class EditorHandlerActivity : ProjectHandlerActivity(), IEditorHandler {
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onDocumentChange(event: DocumentChangeEvent) {
|
||||
// update content modification status
|
||||
onEditorContentChanged()
|
||||
|
||||
val index = findIndexOfEditorByFile(event.file.toFile())
|
||||
if (index == -1) {
|
||||
return
|
||||
|
||||
@@ -118,6 +118,12 @@ public class CodeEditorView extends LinearLayout {
|
||||
final var editor = getEditor();
|
||||
editor.post(() -> {
|
||||
editor.setText(contents, createEditorArgs());
|
||||
|
||||
// editor.setText(...) sets the modified flag to true
|
||||
// but in this case, file is read from disk and hence the contents are not modified at all
|
||||
// so the flag must be changed to unmodified
|
||||
// TODO: Find a better way to check content modification status
|
||||
editor.markUnmodified();
|
||||
postRead();
|
||||
|
||||
selection.validate();
|
||||
|
||||
@@ -722,10 +722,7 @@ public void updateFile(File file) {
|
||||
* @param event The content change event.
|
||||
*/
|
||||
private void handleContentChange(ContentChangeEvent event, Unsubscribe unsubscribe) {
|
||||
if (event.getAction() != ContentChangeEvent.ACTION_SET_NEW_TEXT) {
|
||||
isModified = true;
|
||||
}
|
||||
|
||||
isModified = true;
|
||||
if (getFile() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user