Skip to content

Commit

Permalink
move addTypeAheadModelListener / removeTypeAheadModelListener to …
Browse files Browse the repository at this point in the history
…`JediTermTypeAheadModel`
  • Loading branch information
segrey committed Oct 27, 2024
1 parent 5ecd4d0 commit 14e3d12
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
17 changes: 0 additions & 17 deletions core/src/com/jediterm/terminal/model/TerminalTextBuffer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.jediterm.terminal.TextStyle
import com.jediterm.terminal.model.TerminalLine.TextEntry
import com.jediterm.terminal.model.hyperlinks.TextProcessing
import com.jediterm.terminal.util.CharUtils
import org.jetbrains.annotations.ApiStatus
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.concurrent.CopyOnWriteArrayList
Expand Down Expand Up @@ -76,7 +75,6 @@ class TerminalTextBuffer internal constructor(
private set

private val listeners: MutableList<TerminalModelListener> = CopyOnWriteArrayList()
private val typeAheadListeners: MutableList<TerminalModelListener> = CopyOnWriteArrayList()
private val historyBufferListeners: MutableList<TerminalHistoryBufferListener> = CopyOnWriteArrayList()
private val changesMulticaster: TextBufferChangesMulticaster = TextBufferChangesMulticaster()

Expand Down Expand Up @@ -207,27 +205,12 @@ class TerminalTextBuffer internal constructor(
historyBufferListeners.remove(listener)
}

fun addTypeAheadModelListener(listener: TerminalModelListener) {
typeAheadListeners.add(listener)
}

fun removeTypeAheadModelListener(listener: TerminalModelListener) {
typeAheadListeners.remove(listener)
}

private fun fireModelChangeEvent() {
for (modelListener in listeners) {
modelListener.modelChanged()
}
}

@ApiStatus.Internal
fun fireTypeAheadModelChangeEvent() {
for (modelListener in typeAheadListeners) {
modelListener.modelChanged()
}
}

private fun createEmptyStyleWithCurrentColor(): TextStyle {
return styleState.current.createEmptyWithColors()
}
Expand Down
20 changes: 19 additions & 1 deletion ui/src/com/jediterm/terminal/model/JediTermTypeAheadModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import com.jediterm.terminal.ui.settings.SettingsProvider;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class JediTermTypeAheadModel implements TypeAheadTerminalModel {
private final @NotNull Terminal myTerminal;
private final @NotNull TerminalTextBuffer myTerminalTextBuffer;
private final @NotNull SettingsProvider mySettingsProvider;
private @NotNull TypeAheadTerminalModel.ShellType myShellType = ShellType.Unknown;
private final List<TerminalModelListener> myTypeAheadListeners = new CopyOnWriteArrayList<>();

private boolean isPredictionsApplied = false;

Expand Down Expand Up @@ -44,7 +48,7 @@ public void removeCharacters(int from, int count) {
}

public void forceRedraw() {
myTerminalTextBuffer.fireTypeAheadModelChangeEvent();
fireTypeAheadModelChangeEvent();
}

@Override
Expand Down Expand Up @@ -115,4 +119,18 @@ private void setTypeAheadLine(@NotNull TerminalLine typeAheadTerminalLine) {
TerminalLine terminalLine = myTerminalTextBuffer.getLine(myTerminal.getCursorY() - 1);
terminalLine.myTypeAheadLine = typeAheadTerminalLine;
}

public void addTypeAheadModelListener(@NotNull TerminalModelListener listener) {
myTypeAheadListeners.add(listener);
}

public void removeTypeAheadModelListener(@NotNull TerminalModelListener listener) {
myTypeAheadListeners.remove(listener);
}

private void fireTypeAheadModelChangeEvent() {
for (TerminalModelListener typeAheadListener : myTypeAheadListeners) {
typeAheadListener.modelChanged();
}
}
}
1 change: 1 addition & 0 deletions ui/src/com/jediterm/terminal/ui/JediTermWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public JediTermWidget(int columns, int lines, SettingsProvider settingsProvider)
new JediTermDebouncerImpl(myTypeAheadManager::debounce, TerminalTypeAheadManager.MAX_TERMINAL_DELAY, getExecutorServiceManager());
myTypeAheadManager.setClearPredictionsDebouncer(typeAheadDebouncer);
myTerminalPanel.setTypeAheadManager(myTypeAheadManager);
myTypeAheadTerminalModel.addTypeAheadModelListener(myTerminalPanel::repaint);

myTerminal.setModeEnabled(TerminalMode.AltSendsEscape, mySettingsProvider.altSendsEscape());

Expand Down
1 change: 0 additions & 1 deletion ui/src/com/jediterm/terminal/ui/TerminalPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public TerminalPanel(@NotNull SettingsProvider settingsProvider, @NotNull Termin
enableInputMethods(true);

terminalTextBuffer.addModelListener(this::repaint);
terminalTextBuffer.addTypeAheadModelListener(this::repaint);
terminalTextBuffer.addHistoryBufferListener(() -> myHistoryBufferLineCountChanged.set(true));
}

Expand Down

0 comments on commit 14e3d12

Please sign in to comment.