1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-07-30 09:59:08 +02:00

Rename localEditors to getEditors

The fact that these methods only return local editors (i.e., editors for the local user while hosting a Code With Me session) is an implementation detail
This commit is contained in:
Matt Ellis 2024-02-05 09:39:57 +00:00 committed by Alex Pláte
parent 9d6dc317a4
commit bc808403fb
14 changed files with 24 additions and 24 deletions

View File

@ -38,7 +38,7 @@ internal class PyNotebooksCloseWorkaround : ProjectManagerListener {
override fun projectClosingBeforeSave(project: Project) {
// TODO: Confirm context in CWM scenario
if (injector.globalIjOptions().closenotebooks) {
injector.editorGroup.localEditors().forEach { vimEditor ->
injector.editorGroup.getEditors().forEach { vimEditor ->
val editor = (vimEditor as IjVimEditor).editor
val virtualFile = EditorHelper.getVirtualFile(editor)
if (virtualFile?.extension == "ipynb") {

View File

@ -337,7 +337,7 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
@NotNull
@Override
public Collection<VimEditor> localEditors() {
public Collection<VimEditor> getEditors() {
return getLocalEditors()
.filter(UserDataManager::getVimInitialised)
.map(IjVimEditor::new)
@ -346,7 +346,7 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
@NotNull
@Override
public Collection<VimEditor> localEditors(@NotNull VimDocument buffer) {
public Collection<VimEditor> getEditors(@NotNull VimDocument buffer) {
final Document document = ((IjVimDocument)buffer).getDocument();
return getLocalEditors()
.filter(editor -> UserDataManager.getVimInitialised(editor) && editor.getDocument().equals(document))

View File

@ -98,7 +98,7 @@ public class KeyGroup extends VimKeyGroupBase implements PersistentStateComponen
@Override
public void updateShortcutKeysRegistration() {
for (VimEditor editor : injector.getEditorGroup().localEditors()) {
for (VimEditor editor : injector.getEditorGroup().getEditors()) {
unregisterShortcutKeys(editor);
registerRequiredShortcutKeys(editor);
}

View File

@ -1208,7 +1208,7 @@ public class SearchGroup extends IjVimSearchGroup implements PersistentStateComp
// ClientId.current will be a guest ID), but we don't care - we still need to add/remove highlights for the
// changed text. Make sure we only update local editors, though.
final Document document = event.getDocument();
for (VimEditor vimEditor : injector.getEditorGroup().localEditors(new IjVimDocument(document))) {
for (VimEditor vimEditor : injector.getEditorGroup().getEditors(new IjVimDocument(document))) {
final Editor editor = ((IjVimEditor)vimEditor).getEditor();
Collection<RangeHighlighter> hls = UserDataManager.getVimLastHighlighters(editor);
if (hls == null) {

View File

@ -111,7 +111,7 @@ internal class JumpsListener(val project: Project) : RecentPlacesListener {
}
private fun buildJump(place: PlaceInfo): Jump? {
val editor = injector.editorGroup.localEditors().firstOrNull { it.ij.virtualFile == place.file } ?: return null
val editor = injector.editorGroup.getEditors().firstOrNull { it.ij.virtualFile == place.file } ?: return null
val offset = place.caretPosition?.startOffset ?: return null
val bufferPosition = editor.offsetToBufferPosition(offset)

View File

@ -232,7 +232,7 @@ internal class VimMarkServiceImpl : VimMarkServiceBase(), PersistentStateCompone
* Get any editor for the given document
*
* We need an editor to help calculate offsets for marks, and it doesn't matter which one we use, because they would
* all return the same results. However, we cannot use [VimEditorGroup.localEditors] because the change might have
* all return the same results. However, we cannot use [VimEditorGroup.getEditors] because the change might have
* come from a remote guest and there might not be an open local editor.
*/
private fun getAnyEditorForDocument(doc: Document) =

View File

@ -208,7 +208,7 @@ public class EditorHelper {
if (doc == null) {
return null;
}
return injector.getEditorGroup().localEditors(new IjVimDocument(doc)).stream().findFirst().orElse(null);
return injector.getEditorGroup().getEditors(new IjVimDocument(doc)).stream().findFirst().orElse(null);
}
public static @NotNull String pad(final @NotNull Editor editor,

View File

@ -98,7 +98,7 @@ private fun updateSearchHighlights(
for (project in projectManager.openProjects) {
val current = FileEditorManager.getInstance(project).selectedTextEditor ?: continue
val editors = injector.editorGroup.localEditors(IjVimDocument(current.document))
val editors = injector.editorGroup.getEditors(IjVimDocument(current.document))
for (vimEditor in editors) {
val editor = (vimEditor as IjVimEditor).editor
if (editor.project != project) {

View File

@ -232,7 +232,7 @@ internal object VimListenerManager {
}
fun removeAll() {
injector.editorGroup.localEditors().forEach { editor ->
injector.editorGroup.getEditors().forEach { editor ->
remove(editor.ij)
}
}

View File

@ -369,7 +369,7 @@ public class ExOutputPanel extends JPanel {
// This listener is only invoked for local scenarios, and we only need to update local editor UI. This will invoke
// updateUI on the output pane and it's child components
for (VimEditor vimEditor : injector.getEditorGroup().localEditors()) {
for (VimEditor vimEditor : injector.getEditorGroup().getEditors()) {
Editor editor = ((IjVimEditor)vimEditor).getEditor();
if (!ExOutputPanel.isPanelActive(editor)) continue;
IJSwingUtilities.updateComponentTreeUI(ExOutputPanel.getInstance(editor));

View File

@ -14,7 +14,7 @@ public interface VimEditorGroup {
/**
* Get a collection of all editors, including those that have not yet been initialised.
*
* You probably don't want to use this - use [localEditors]!
* You probably don't want to use this - use [getEditors]!
*
* This function is only useful during plugin initialisation. It will return all currently open editors, including
* those that have not yet been initialised, so the plugin can correctly initialise them. When the plugin starts, the
@ -40,7 +40,7 @@ public interface VimEditorGroup {
*
* Also note that it is possible for multiple editors in different projects to open the same file (document/buffer).
*/
public fun localEditors(): Collection<VimEditor>
public fun getEditors(): Collection<VimEditor>
/**
* Get a collection of all initialised editors for the given buffer
@ -54,5 +54,5 @@ public interface VimEditorGroup {
* Implementors should take care to only return "local" editors. I.e. for IntelliJ, this function will not include
* hidden editors that are used to handle requests from Code With Me guests.
*/
public fun localEditors(buffer: VimDocument): Collection<VimEditor>
public fun getEditors(buffer: VimDocument): Collection<VimEditor>
}

View File

@ -136,7 +136,7 @@ public abstract class VimMarkServiceBase : VimMarkService {
}
override fun getAllMarksForFile(editor: VimEditor): List<Pair<ImmutableVimCaret?, Set<Mark>>> {
val localMarks = injector.editorGroup.localEditors()
val localMarks = injector.editorGroup.getEditors()
.filter { it.getPath() == editor.getPath() }
.flatMap { it.carets() }
.map { Pair(it, getAllLocalMarks(it)) }
@ -413,7 +413,7 @@ public abstract class VimMarkServiceBase : VimMarkService {
}
override fun resetAllMarks() {
for (editor in injector.editorGroup.localEditors()) {
for (editor in injector.editorGroup.getEditors()) {
editor.carets().forEach {
resetAllMarksForCaret(it)
}

View File

@ -135,7 +135,7 @@ public abstract class VimOptionGroupBase : VimOptionGroup {
resetAllOptions(injector.fallbackWindow)
// During testing, we do not expect to have any editors, so this collection is usually empty
injector.editorGroup.localEditors().forEach { resetAllOptions(it) }
injector.editorGroup.getEditors().forEach { resetAllOptions(it) }
}
override fun addOption(option: Option<out VimDataType>) {
@ -192,7 +192,7 @@ public abstract class VimOptionGroupBase : VimOptionGroup {
if (option.declaredScope != LOCAL_TO_WINDOW) {
storage.setOptionValue(option, OptionAccessScope.GLOBAL(null), option.defaultValue)
}
injector.editorGroup.localEditors().forEach { editor ->
injector.editorGroup.getEditors().forEach { editor ->
when (option.declaredScope) {
GLOBAL -> { }
LOCAL_TO_BUFFER,
@ -612,7 +612,7 @@ private class OptionListenersImpl(private val optionStorage: OptionStorage, priv
*/
private fun onGlobalOptionChanged(optionName: String) {
globalOptionListeners[optionName]?.forEach { it.onGlobalOptionChanged() }
fireEffectiveValueChanged(optionName, editorGroup.localEditors())
fireEffectiveValueChanged(optionName, editorGroup.getEditors())
}
/**
@ -621,7 +621,7 @@ private class OptionListenersImpl(private val optionStorage: OptionStorage, priv
* Notifies all open editors for the current buffer (document).
*/
private fun onLocalToBufferOptionChanged(option: Option<out VimDataType>, editor: VimEditor) {
fireEffectiveValueChanged(option.name, editorGroup.localEditors(editor.document))
fireEffectiveValueChanged(option.name, editorGroup.getEditors(editor.document))
}
/**
@ -639,7 +639,7 @@ private class OptionListenersImpl(private val optionStorage: OptionStorage, priv
* This will notify all open editors where the option is not locally set.
*/
private fun onGlobalLocalOptionGlobalValueChanged(option: Option<out VimDataType>) {
val affectedEditors = editorGroup.localEditors().filter { optionStorage.isUnsetValue(option, it) }
val affectedEditors = editorGroup.getEditors().filter { optionStorage.isUnsetValue(option, it) }
fireEffectiveValueChanged(option.name, affectedEditors)
}
@ -659,13 +659,13 @@ private class OptionListenersImpl(private val optionStorage: OptionStorage, priv
// We could get essentially the same behaviour by calling onGlobalLocalOptionGlobalValueChanged followed by
// onLocalXxxOptionChanged, but that would notify editors for string-based options twice.
val affectedEditors = mutableListOf<VimEditor>()
affectedEditors.addAll(editorGroup.localEditors().filter { optionStorage.isUnsetValue(option, it) })
affectedEditors.addAll(editorGroup.getEditors().filter { optionStorage.isUnsetValue(option, it) })
if (option.declaredScope == GLOBAL_OR_LOCAL_TO_WINDOW) {
if (!optionStorage.isUnsetValue(option, editor)) affectedEditors.add(editor)
}
else if (option.declaredScope == GLOBAL_OR_LOCAL_TO_BUFFER) {
affectedEditors.addAll(editorGroup.localEditors(editor.document).filter { !optionStorage.isUnsetValue(option, it) })
affectedEditors.addAll(editorGroup.getEditors(editor.document).filter { !optionStorage.isUnsetValue(option, it) })
}
fireEffectiveValueChanged(option.name, affectedEditors)

View File

@ -121,7 +121,7 @@ public class VimStateMachineImpl(private val editor: VimEditor?) : VimStateMachi
editor.updateCaretsVisualAttributes()
editor.updateCaretsVisualPosition()
} else {
injector.editorGroup.localEditors().forEach { editor ->
injector.editorGroup.getEditors().forEach { editor ->
editor.updateCaretsVisualAttributes()
editor.updateCaretsVisualPosition()
}