Record a new selection from the IDE.
(self, selection: IDESelection)
| 46 | return [e.selection for e in reversed(self._history)] |
| 47 | |
| 48 | def update(self, selection: IDESelection) -> None: |
| 49 | """Record a new selection from the IDE.""" |
| 50 | entry = SelectionEntry(selection=selection, timestamp=time.time()) |
| 51 | self._history.append(entry) |
| 52 | if len(self._history) > self._max_history: |
| 53 | self._history = self._history[-self._max_history:] |
| 54 | for listener in self._listeners: |
| 55 | try: |
| 56 | listener(selection) |
| 57 | except Exception: |
| 58 | logger.exception("Error in selection listener") |
| 59 | |
| 60 | def on_selection(self, listener: Callable[[IDESelection], None]) -> Callable[[], None]: |
| 61 | """Register a selection change listener. Returns unsubscribe function.""" |