Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 54
ADFA-2657 | Fix editor threading and selection logic#980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
48 changes: 27 additions & 21 deletions
48 app/src/main/java/com/itsaky/androidide/activities/editor/EditorHandlerActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -62,7 +62,6 @@ import com.itsaky.androidide.models.Range | ||
| import com.itsaky.androidide.models.SaveResult | ||
| import com.itsaky.androidide.plugins.manager.fragment.PluginFragmentFactory | ||
| import com.itsaky.androidide.plugins.manager.ui.PluginEditorTabManager | ||
| import com.itsaky.androidide.preferences.internal.GeneralPreferences | ||
| import com.itsaky.androidide.projects.ProjectManagerImpl | ||
| import com.itsaky.androidide.projects.builder.BuildResult | ||
| import com.itsaky.androidide.tasks.executeAsync | ||
| @@ -75,7 +74,6 @@ import com.itsaky.androidide.utils.flashSuccess | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.NonCancellable | ||
| import kotlinx.coroutines.launch | ||
| import kotlinx.coroutines.runBlocking | ||
| import kotlinx.coroutines.withContext | ||
| import org.adfa.constants.CONTENT_KEY | ||
| import org.greenrobot.eventbus.Subscribe | ||
| @@ -454,37 +452,35 @@ open class EditorHandlerActivity : | ||
| file: File, | ||
| selection: Range?, | ||
| ) { | ||
| openFile(file, selection) | ||
| lifecycleScope.launch { | ||
| val editorView = openFile(file, selection) | ||
| getEditorForFile(file)?.editor?.also { editor -> | ||
| editor.postInLifecycle { | ||
| if (selection == null) { | ||
| editor.setSelection(0, 0) | ||
| return@postInLifecycle | ||
| editorView?.editor?.also { editor -> | ||
| editor.postInLifecycle { | ||
| if (selection == null) { | ||
| editor.setSelection(0, 0) | ||
| return@postInLifecycle | ||
| } | ||
| editor.validateRange(selection) | ||
| editor.setSelection(selection) | ||
| } | ||
| editor.validateRange(selection) | ||
| editor.setSelection(selection) | ||
| } | ||
| } | ||
| } | ||
| override fun openFile( | ||
| override suspend fun openFile( | ||
| file: File, | ||
| selection: Range?, | ||
| ): CodeEditorView? { | ||
| ): CodeEditorView? = withContext(Dispatchers.Main) { | ||
| val range = selection ?: Range.NONE | ||
| val isImage = runBlocking { | ||
| withContext(Dispatchers.IO) { ImageUtils.isImage(file) } | ||
| } | ||
| val isImage = withContext(Dispatchers.IO) { ImageUtils.isImage(file) } | ||
| if (isImage) { | ||
| openImage(this, file) | ||
| return null | ||
| openImage(this@EditorHandlerActivity, file) | ||
| return@withContext null | ||
| } | ||
| val fileIndex = openFileAndGetIndex(file, range) | ||
| if (fileIndex < 0) return null | ||
| if (fileIndex < 0) return@withContext null | ||
| editorViewModel.startDrawerOpened = false | ||
| editorViewModel.displayedFileIndex = fileIndex | ||
| @@ -495,14 +491,24 @@ open class EditorHandlerActivity : | ||
| tab.select() | ||
| } | ||
| return try { | ||
| return@withContext try { | ||
| getEditorAtIndex(fileIndex) | ||
| } catch (th: Throwable) { | ||
| log.error("Unable to get editor at file index {}", fileIndex, th) | ||
| null | ||
| } | ||
jatezzz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| fun openFileAsync( | ||
| file: File, | ||
| selection: Range? = null, | ||
| onResult: (CodeEditorView?) -> Unit | ||
| ) { | ||
| lifecycleScope.launch { | ||
| onResult(openFile(file, selection)) | ||
| } | ||
| } | ||
| override fun openFileAndGetIndex( | ||
| file: File, | ||
| selection: Range?, | ||
6 changes: 5 additions & 1 deletion
6 app/src/main/java/com/itsaky/androidide/handlers/FileTreeActionHandler.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4 app/src/main/java/com/itsaky/androidide/interfaces/IEditorHandler.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10 app/src/main/java/com/itsaky/androidide/lsp/IDELanguageClientImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -252,10 +252,12 @@ private Boolean applyActionEdits(@Nullable final IDEEditor editor, final CodeAct | ||
| } else { | ||
| // Edit is in some other file which is not opened | ||
| // open that file and perform the edit | ||
| openedFrag = activity.openFile(file); | ||
| if (openedFrag != null && openedFrag.getEditor() != null) { | ||
| editInEditor(openedFrag.getEditor(), edit); | ||
| } | ||
| activity.openFileAsync(file, null, openedEditor -> { | ||
| if (openedEditor != null && openedEditor.getEditor() != null) { | ||
| editInEditor(openedEditor.getEditor(), edit); | ||
| } | ||
| return kotlin.Unit.INSTANCE; | ||
| }); | ||
jatezzz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.