Skip to content

Commit

Permalink
Rename localEditors to getEditors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
citizenmatt committed Feb 23, 2024
1 parent da40f49 commit 79b5543
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/maddyhome/idea/vim/PluginStartup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/maddyhome/idea/vim/group/EditorGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public Integer getMaxLineNumber(@NotNull Editor editor) {

@NotNull
@Override
public Collection<VimEditor> localEditors() {
public Collection<VimEditor> getEditors() {
return getLocalEditors()
.filter(UserDataManager::getVimInitialised)
.map(IjVimEditor::new)
Expand All @@ -346,7 +346,7 @@ public Collection<VimEditor> localEditors() {

@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))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/maddyhome/idea/vim/group/KeyGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public boolean showKeyMappings(@NotNull Set<? extends MappingMode> modes, @NotNu

@Override
public void updateShortcutKeysRegistration() {
for (VimEditor editor : injector.getEditorGroup().localEditors()) {
for (VimEditor editor : injector.getEditorGroup().getEditors()) {
unregisterShortcutKeys(editor);
registerRequiredShortcutKeys(editor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ public void documentChanged(@NotNull DocumentEvent event) {
// 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static int getVisualColumnAtRightOfDisplay(final @NotNull Editor editor,
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ internal object VimListenerManager {
}

fun removeAll() {
injector.editorGroup.localEditors().forEach { editor ->
injector.editorGroup.getEditors().forEach { editor ->
remove(editor.ij)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/maddyhome/idea/vim/ui/ExOutputPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void lookAndFeelChanged(@NotNull LafManager source) {

// 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())
}

/**
Expand All @@ -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))
}

/**
Expand All @@ -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)
}

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 79b5543

Please sign in to comment.