codis 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codis-1.1.1.dist-info/METADATA +194 -0
- codis-1.1.1.dist-info/RECORD +329 -0
- codis-1.1.1.dist-info/WHEEL +5 -0
- codis-1.1.1.dist-info/entry_points.txt +5 -0
- codis-1.1.1.dist-info/licenses/LICENSE +21 -0
- codis-1.1.1.dist-info/top_level.txt +2 -0
- run.py +190 -0
- src/__init__.py +1 -0
- src/__main__.py +81 -0
- src/_app_build.py +1507 -0
- src/_app_editor.py +1274 -0
- src/_app_kui.py +825 -0
- src/_app_lsp.py +625 -0
- src/_app_recovery.py +189 -0
- src/_app_settings.py +1385 -0
- src/_app_tools.py +2471 -0
- src/_app_webpreview.py +126 -0
- src/_font_safety.py +127 -0
- src/_shells.py +172 -0
- src/app.py +1488 -0
- src/chat/__init__.py +1 -0
- src/chat/adapters/__init__.py +33 -0
- src/chat/adapters/base.py +209 -0
- src/chat/adapters/discord.py +190 -0
- src/chat/adapters/http.py +78 -0
- src/chat/adapters/irc.py +360 -0
- src/chat/adapters/matrix.py +219 -0
- src/chat/adapters/mattermost.py +178 -0
- src/chat/adapters/mqtt.py +165 -0
- src/chat/adapters/slack.py +204 -0
- src/chat/adapters/telegram.py +117 -0
- src/chat/adapters/ws.py +154 -0
- src/chat/adapters/xmpp.py +337 -0
- src/chat/history.py +76 -0
- src/chat/models.py +207 -0
- src/chat/probe.py +79 -0
- src/chat/session.py +446 -0
- src/chat/util.py +125 -0
- src/collab/__init__.py +1 -0
- src/collab/net.py +411 -0
- src/collab/ot.py +311 -0
- src/collab/session.py +141 -0
- src/collab/tk_adapter.py +134 -0
- src/config.py +335 -0
- src/constants.py +2552 -0
- src/dep_catalog.py +446 -0
- src/diff/__init__.py +1 -0
- src/diff/engine.py +247 -0
- src/dpi.py +30 -0
- src/editor/__init__.py +1 -0
- src/editor/_pane_lsp.py +2937 -0
- src/editor/_pane_utils.py +171 -0
- src/editor/autocomplete.py +607 -0
- src/editor/code_folding.py +836 -0
- src/editor/color_preview.py +382 -0
- src/editor/complexity_lens.py +281 -0
- src/editor/diff_pane.py +623 -0
- src/editor/file_watcher.py +144 -0
- src/editor/focus_block.py +236 -0
- src/editor/heatmap.py +141 -0
- src/editor/inlay_hints.py +366 -0
- src/editor/inline_blame.py +429 -0
- src/editor/kdocs.py +3376 -0
- src/editor/large_file.py +488 -0
- src/editor/ligatures.py +180 -0
- src/editor/line_numbers.py +598 -0
- src/editor/minimap.py +691 -0
- src/editor/multi_cursor.py +269 -0
- src/editor/pane.py +2082 -0
- src/editor/rhythm.py +206 -0
- src/editor/save_hooks.py +43 -0
- src/editor/smart_selection.py +425 -0
- src/editor/smart_tips.py +719 -0
- src/editor/snippets.py +411 -0
- src/editor/sticky_note_gutter.py +410 -0
- src/editor/sticky_scroll.py +385 -0
- src/editor/suggest.py +464 -0
- src/editor/text_transforms.py +310 -0
- src/editor/vim_mode.py +1074 -0
- src/events/__init__.py +84 -0
- src/events/bus.py +427 -0
- src/events/correlator.py +244 -0
- src/events/kinds.py +125 -0
- src/events/pipeline.py +264 -0
- src/events/stream.py +416 -0
- src/events/window.py +204 -0
- src/extcompat/__init__.py +19 -0
- src/extcompat/code/__init__.py +13 -0
- src/extcompat/code/consent.py +162 -0
- src/extcompat/code/host.py +353 -0
- src/extcompat/code/hosts/py_host.py +763 -0
- src/extcompat/code/locate.py +105 -0
- src/extcompat/code/manager.py +325 -0
- src/extcompat/code/permissions.py +154 -0
- src/extcompat/code/sandbox.py +60 -0
- src/extcompat/colors.py +131 -0
- src/extcompat/common.py +184 -0
- src/extcompat/cson.py +269 -0
- src/extcompat/formats/__init__.py +22 -0
- src/extcompat/formats/_tm.py +189 -0
- src/extcompat/formats/_util.py +31 -0
- src/extcompat/formats/base16.py +66 -0
- src/extcompat/formats/brackets.py +172 -0
- src/extcompat/formats/eclipse.py +193 -0
- src/extcompat/formats/emacs.py +361 -0
- src/extcompat/formats/geany.py +147 -0
- src/extcompat/formats/generic.py +184 -0
- src/extcompat/formats/gtksource.py +117 -0
- src/extcompat/formats/helix.py +91 -0
- src/extcompat/formats/jetbrains.py +343 -0
- src/extcompat/formats/kate.py +130 -0
- src/extcompat/formats/micro.py +131 -0
- src/extcompat/formats/nano.py +111 -0
- src/extcompat/formats/notepadpp.py +140 -0
- src/extcompat/formats/pulsar.py +165 -0
- src/extcompat/formats/pyides.py +163 -0
- src/extcompat/formats/sublime.py +340 -0
- src/extcompat/jsonc.py +65 -0
- src/extcompat/lessish.py +128 -0
- src/extcompat/manager.py +122 -0
- src/extcompat/market/__init__.py +63 -0
- src/extcompat/market/sources.py +211 -0
- src/extcompat/model.py +88 -0
- src/extcompat/net.py +228 -0
- src/extcompat/openvsx.py +63 -0
- src/extcompat/readers.py +362 -0
- src/extcompat/registry.py +73 -0
- src/extcompat/safexml.py +63 -0
- src/extcompat/sexp.py +187 -0
- src/extcompat/sources.py +105 -0
- src/extcompat/store.py +276 -0
- src/extcompat/textmate.py +214 -0
- src/extcompat/themes.py +487 -0
- src/extcompat/yamlite.py +294 -0
- src/fileio.py +94 -0
- src/fs_ops.py +106 -0
- src/i18n.py +233 -0
- src/ia/__init__.py +1 -0
- src/ia/actions.py +295 -0
- src/ia/approval_gate.py +672 -0
- src/ia/checkpoints.py +308 -0
- src/ia/context_builder.py +921 -0
- src/ia/dialdiff.py +408 -0
- src/ia/iaspace.py +2078 -0
- src/ia/pair.py +296 -0
- src/ia/providers.py +954 -0
- src/ia/session.py +335 -0
- src/ia/toolbox.py +2524 -0
- src/launcher_actions.py +204 -0
- src/lint/__init__.py +1 -0
- src/lint/manager.py +1058 -0
- src/locales/.translate_manifest.json +64170 -0
- src/locales/de.json +4936 -0
- src/locales/en.json +4936 -0
- src/locales/es.json +4936 -0
- src/locales/fr.json +4936 -0
- src/locales/it.json +4936 -0
- src/locales/ja.json +4936 -0
- src/locales/ko.json +4936 -0
- src/locales/nl.json +4936 -0
- src/locales/pl.json +4936 -0
- src/locales/pt-BR.json +4936 -0
- src/locales/ru.json +4936 -0
- src/locales/tr.json +4936 -0
- src/locales/uk.json +4936 -0
- src/locales/zh-CN.json +4936 -0
- src/lsp/__init__.py +26 -0
- src/lsp/client.py +2300 -0
- src/lsp/dap_client.py +480 -0
- src/lsp/edits.py +84 -0
- src/lsp/framing.py +73 -0
- src/lsp/protocol.py +931 -0
- src/main.py +260 -0
- src/memtrim.py +91 -0
- src/plugins/__init__.py +1 -0
- src/plugins/api.py +1761 -0
- src/plugins/loader.py +571 -0
- src/plugins/process_runner.py +519 -0
- src/plugins/registry.py +342 -0
- src/plugins/safety.py +367 -0
- src/plugins/startup.py +195 -0
- src/plugins/store.py +1178 -0
- src/proc_registry.py +278 -0
- src/pyexec.py +394 -0
- src/recovery.py +259 -0
- src/stall_trace.py +92 -0
- src/standalone.py +1070 -0
- src/startup_profile.py +35 -0
- src/syntax/__init__.py +1 -0
- src/syntax/highlighter.py +776 -0
- src/syntax/patterns.py +584 -0
- src/system_profile.py +430 -0
- src/terminal/backends.py +658 -0
- src/terminal/internal.py +346 -0
- src/terminal/keys.py +138 -0
- src/terminal/palette.py +67 -0
- src/terminal/session.py +283 -0
- src/terminal/shells.py +79 -0
- src/terminal/view.py +489 -0
- src/terminal/vt.py +870 -0
- src/textfmt.py +22 -0
- src/theme/__init__.py +1 -0
- src/theme/base.py +1281 -0
- src/theme/colors.py +49 -0
- src/theme/manager.py +602 -0
- src/theme/utils.py +312 -0
- src/toolbox.py +329 -0
- src/trash_core.py +531 -0
- src/ui/__init__.py +1 -0
- src/ui/_perf_utils.py +285 -0
- src/ui/_persistence_utils.py +93 -0
- src/ui/accessibility.py +843 -0
- src/ui/activity_bar.py +860 -0
- src/ui/app_embed.py +434 -0
- src/ui/archive_panel.py +608 -0
- src/ui/bookmarks.py +314 -0
- src/ui/breadcrumb.py +383 -0
- src/ui/calculator_panel.py +982 -0
- src/ui/calendar_panel.py +1218 -0
- src/ui/chat_panel.py +1271 -0
- src/ui/chat_profile_dialog.py +278 -0
- src/ui/chat_render.py +128 -0
- src/ui/clock_panel.py +810 -0
- src/ui/code_outline.py +364 -0
- src/ui/code_runner.py +729 -0
- src/ui/code_stats.py +546 -0
- src/ui/collab_panel.py +1009 -0
- src/ui/color_picker.py +547 -0
- src/ui/command_palette.py +452 -0
- src/ui/cursor_manager.py +750 -0
- src/ui/custom_keywords_panel.py +413 -0
- src/ui/debug_panel.py +1037 -0
- src/ui/dependency_graph.py +692 -0
- src/ui/diff_panel.py +381 -0
- src/ui/docs_panel.py +514 -0
- src/ui/doom_embed.py +349 -0
- src/ui/dropdown.py +321 -0
- src/ui/easter_eggs.py +979 -0
- src/ui/env_manager.py +666 -0
- src/ui/extcode_bridge.py +215 -0
- src/ui/extcode_dialogs.py +412 -0
- src/ui/extcompat_dialog.py +583 -0
- src/ui/file_timeline.py +319 -0
- src/ui/file_tree.py +1208 -0
- src/ui/find_in_files.py +1355 -0
- src/ui/flowchart_panel.py +727 -0
- src/ui/formatter_panel.py +490 -0
- src/ui/git_auth.py +763 -0
- src/ui/git_clone_dialog.py +487 -0
- src/ui/git_panel.py +1483 -0
- src/ui/grab_safe.py +84 -0
- src/ui/internal_python_dialog.py +98 -0
- src/ui/k_ui/__init__.py +1305 -0
- src/ui/k_ui/_bgrenderer.py +317 -0
- src/ui/k_ui/_colors.py +213 -0
- src/ui/k_ui/_dock.py +545 -0
- src/ui/k_ui/_easter.py +290 -0
- src/ui/k_ui/_engine.py +5448 -0
- src/ui/k_ui/_perf.py +333 -0
- src/ui/k_ui/_tkutil.py +7 -0
- src/ui/k_ui/_tooltip.py +365 -0
- src/ui/k_ui/_widgets.py +1204 -0
- src/ui/k_ui/_world.py +837 -0
- src/ui/key_remapper.py +856 -0
- src/ui/launcher.py +1252 -0
- src/ui/lazy_panel.py +73 -0
- src/ui/macro_recorder.py +610 -0
- src/ui/menu_bar.py +898 -0
- src/ui/output_panel.py +321 -0
- src/ui/paint_canvas.py +1000 -0
- src/ui/paint_engine.py +535 -0
- src/ui/paint_panel.py +888 -0
- src/ui/panel_detach.py +112 -0
- src/ui/performance_panel.py +861 -0
- src/ui/pip_manager.py +1758 -0
- src/ui/plugin_panel.py +1586 -0
- src/ui/pomodoro_panel.py +447 -0
- src/ui/problems.py +566 -0
- src/ui/process_manager.py +1657 -0
- src/ui/project_templates.py +775 -0
- src/ui/recovery_dialog.py +122 -0
- src/ui/regex_playground.py +304 -0
- src/ui/remote_adapters.py +1398 -0
- src/ui/remote_browser.py +1224 -0
- src/ui/remote_profile_dialog.py +342 -0
- src/ui/render_panel.py +1293 -0
- src/ui/rest_client.py +549 -0
- src/ui/scratchpad.py +548 -0
- src/ui/search_bar.py +1274 -0
- src/ui/settings_editor.py +3349 -0
- src/ui/settings_window.py +1554 -0
- src/ui/snippets_panel.py +597 -0
- src/ui/sql_studio.py +1815 -0
- src/ui/status_bar.py +438 -0
- src/ui/tab_bar.py +654 -0
- src/ui/task_manager.py +1773 -0
- src/ui/terminal.py +525 -0
- src/ui/theme_preview_panel.py +851 -0
- src/ui/thread_safe_tk.py +152 -0
- src/ui/time_tracker.py +574 -0
- src/ui/tkbind.py +43 -0
- src/ui/todo_panel.py +358 -0
- src/ui/toolbox_panels.py +658 -0
- src/ui/trash_manager.py +657 -0
- src/ui/ui_scale.py +294 -0
- src/ui/ux_enhancements.py +41 -0
- src/ui/web_preview.py +397 -0
- src/ui/webdev.py +630 -0
- src/ui/welcome.py +567 -0
- src/ui/window_embed.py +1500 -0
- src/ui/wizard.py +1550 -0
- src/ui/workspace_switcher.py +418 -0
- src/ui/workspace_trust.py +370 -0
- src/ui/zen_audio.py +354 -0
- src/ui/zen_media.py +2271 -0
- src/ui/zen_media_client.py +303 -0
- src/ui/zen_media_host.py +329 -0
- src/ui/zen_player.py +907 -0
- src/ui/zen_player_widgets.py +700 -0
- src/updater/__init__.py +11 -0
- src/updater/assets.py +145 -0
- src/updater/backup.py +101 -0
- src/updater/channel.py +221 -0
- src/updater/dialog.py +492 -0
- src/updater/integrity.py +111 -0
- src/updater/manager.py +727 -0
- src/updater/result.py +114 -0
- src/venv_runtime.py +531 -0
- src/workspace_state.py +25 -0
src/editor/rhythm.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""Codis - CodeRhythm: análise de ritmo de digitação em tempo real.
|
|
2
|
+
|
|
3
|
+
Funcionalidade exclusiva do Codis.
|
|
4
|
+
|
|
5
|
+
Rastreia o ritmo de digitação do desenvolvedor e exibe estatísticas
|
|
6
|
+
de produtividade em tempo real:
|
|
7
|
+
|
|
8
|
+
- WPM (words per minute) de código.
|
|
9
|
+
- "Flow state" detector: identifica quando o desenvolvedor está em estado
|
|
10
|
+
de fluxo (digitação regular, sem longas pausas).
|
|
11
|
+
- Mapa de padrões de pausa (onde o desenvolvedor hesita).
|
|
12
|
+
- Sequências de edições repetitivas (refatoração em loop).
|
|
13
|
+
- Estimativa de tempo restante para completar o arquivo baseado no ritmo.
|
|
14
|
+
|
|
15
|
+
Integração
|
|
16
|
+
----------
|
|
17
|
+
O CodeRhythm recebe keystroke events via :meth:`record_keystroke` e expõe
|
|
18
|
+
métricas via :meth:`metrics`. Integrado ao StatusBar e ao EventBus.
|
|
19
|
+
|
|
20
|
+
Uso
|
|
21
|
+
---
|
|
22
|
+
rhythm = CodeRhythm()
|
|
23
|
+
rhythm.record_keystroke() # chamado a cada KeyPress no editor
|
|
24
|
+
m = rhythm.metrics()
|
|
25
|
+
print(m["wpm"], m["flow_state"]) # ex: 42.3, "flow"
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
import logging
|
|
31
|
+
import threading
|
|
32
|
+
import time
|
|
33
|
+
from collections import deque
|
|
34
|
+
from collections.abc import Callable
|
|
35
|
+
from dataclasses import dataclass
|
|
36
|
+
|
|
37
|
+
logger = logging.getLogger(__name__)
|
|
38
|
+
|
|
39
|
+
_WPM_WINDOW_S = 60.0
|
|
40
|
+
_CHARS_PER_WORD = 5
|
|
41
|
+
_FLOW_BREAK_S = 3.0
|
|
42
|
+
_SESSION_RESET_S = 120.0
|
|
43
|
+
_MIN_KEYSTROKES = 10
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class RhythmMetrics:
|
|
48
|
+
"""Snapshot das métricas de ritmo em um dado momento."""
|
|
49
|
+
|
|
50
|
+
wpm: float = 0.0
|
|
51
|
+
cpm: float = 0.0
|
|
52
|
+
flow_state: str = "idle"
|
|
53
|
+
session_chars: int = 0
|
|
54
|
+
session_s: float = 0.0
|
|
55
|
+
pause_count: int = 0
|
|
56
|
+
streak_s: float = 0.0
|
|
57
|
+
last_pause_s: float = 0.0
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class CodeRhythm:
|
|
61
|
+
"""Rastreador de ritmo de digitação com detecção de flow state.
|
|
62
|
+
|
|
63
|
+
Thread-safe: ``record_keystroke()`` pode ser chamado da thread da UI.
|
|
64
|
+
``metrics()`` pode ser chamado de qualquer thread.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def __init__(
|
|
68
|
+
self,
|
|
69
|
+
on_flow_change: Callable[[str], None] | None = None,
|
|
70
|
+
) -> None:
|
|
71
|
+
"""Inicializa o rastreador de ritmo.
|
|
72
|
+
|
|
73
|
+
Parameters
|
|
74
|
+
----------
|
|
75
|
+
on_flow_change:
|
|
76
|
+
Callback chamado quando o flow state muda.
|
|
77
|
+
Recebe a nova string de estado: ``"idle"``, ``"warming"``,
|
|
78
|
+
``"flow"`` ou ``"deep_flow"``.
|
|
79
|
+
"""
|
|
80
|
+
self._lock = threading.Lock()
|
|
81
|
+
self._on_flow_change = on_flow_change
|
|
82
|
+
|
|
83
|
+
self._timestamps: deque[float] = deque()
|
|
84
|
+
|
|
85
|
+
self._session_start: float | None = None
|
|
86
|
+
self._session_chars: int = 0
|
|
87
|
+
self._pause_count: int = 0
|
|
88
|
+
self._last_ks: float | None = None
|
|
89
|
+
self._streak_start: float | None = None
|
|
90
|
+
self._last_pause_s: float = 0.0
|
|
91
|
+
self._flow_state: str = "idle"
|
|
92
|
+
|
|
93
|
+
def record_keystroke(self, char: str = "") -> None:
|
|
94
|
+
"""Registra um keystroke. Deve ser chamado a cada tecla no editor."""
|
|
95
|
+
if char and not char.isprintable():
|
|
96
|
+
return
|
|
97
|
+
now = time.monotonic()
|
|
98
|
+
with self._lock:
|
|
99
|
+
cutoff = now - _WPM_WINDOW_S
|
|
100
|
+
while self._timestamps and self._timestamps[0] < cutoff:
|
|
101
|
+
self._timestamps.popleft()
|
|
102
|
+
self._timestamps.append(now)
|
|
103
|
+
|
|
104
|
+
if self._last_ks is not None:
|
|
105
|
+
gap = now - self._last_ks
|
|
106
|
+
if gap >= _FLOW_BREAK_S:
|
|
107
|
+
self._pause_count += 1
|
|
108
|
+
self._last_pause_s = gap
|
|
109
|
+
self._streak_start = now
|
|
110
|
+
if gap >= _SESSION_RESET_S:
|
|
111
|
+
self._session_chars = 0
|
|
112
|
+
self._session_start = now
|
|
113
|
+
self._pause_count = 0
|
|
114
|
+
else:
|
|
115
|
+
self._session_start = now
|
|
116
|
+
self._streak_start = now
|
|
117
|
+
|
|
118
|
+
self._last_ks = now
|
|
119
|
+
if self._session_start is None:
|
|
120
|
+
self._session_start = now
|
|
121
|
+
self._session_chars += 1
|
|
122
|
+
|
|
123
|
+
new_state = self._compute_flow(now)
|
|
124
|
+
old_state = self._flow_state
|
|
125
|
+
self._flow_state = new_state
|
|
126
|
+
|
|
127
|
+
if new_state != old_state and self._on_flow_change:
|
|
128
|
+
try:
|
|
129
|
+
self._on_flow_change(new_state)
|
|
130
|
+
except Exception:
|
|
131
|
+
logger.debug("record_keystroke: erro ignorado", exc_info=True)
|
|
132
|
+
|
|
133
|
+
def _window_cpm(self) -> float:
|
|
134
|
+
"""Calcula caracteres por minuto a partir da janela de timestamps atual.
|
|
135
|
+
|
|
136
|
+
Deve ser chamado com ``self._lock`` já adquirido. Usado tanto por
|
|
137
|
+
:meth:`metrics` quanto por :meth:`_compute_flow`, que derivam suas
|
|
138
|
+
respectivas taxas (CPM/WPM) da mesma janela deslizante de
|
|
139
|
+
keystrokes.
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
Caracteres por minuto, ou ``0.0`` se não houver amostras
|
|
143
|
+
suficientes para estimar uma taxa.
|
|
144
|
+
"""
|
|
145
|
+
if len(self._timestamps) < 2:
|
|
146
|
+
return 0.0
|
|
147
|
+
window_s = self._timestamps[-1] - self._timestamps[0]
|
|
148
|
+
if window_s <= 0:
|
|
149
|
+
return 0.0
|
|
150
|
+
return (len(self._timestamps) / window_s) * 60.0
|
|
151
|
+
|
|
152
|
+
def metrics(self) -> RhythmMetrics:
|
|
153
|
+
"""Retorna um snapshot das métricas de ritmo atuais."""
|
|
154
|
+
now = time.monotonic()
|
|
155
|
+
with self._lock:
|
|
156
|
+
if len(self._timestamps) < 2:
|
|
157
|
+
return RhythmMetrics(flow_state=self._flow_state)
|
|
158
|
+
|
|
159
|
+
cpm = self._window_cpm()
|
|
160
|
+
wpm = cpm / _CHARS_PER_WORD
|
|
161
|
+
session_s = (
|
|
162
|
+
now - self._session_start) if self._session_start else 0.0
|
|
163
|
+
streak_s = (
|
|
164
|
+
now - self._streak_start) if self._streak_start else 0.0
|
|
165
|
+
return RhythmMetrics(
|
|
166
|
+
wpm=round(wpm, 1),
|
|
167
|
+
cpm=round(cpm, 1),
|
|
168
|
+
flow_state=self._flow_state,
|
|
169
|
+
session_chars=self._session_chars,
|
|
170
|
+
session_s=round(session_s, 1),
|
|
171
|
+
pause_count=self._pause_count,
|
|
172
|
+
streak_s=round(streak_s, 1),
|
|
173
|
+
last_pause_s=round(self._last_pause_s, 1),
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
def reset(self) -> None:
|
|
177
|
+
"""Zera todas as métricas."""
|
|
178
|
+
with self._lock:
|
|
179
|
+
self._timestamps.clear()
|
|
180
|
+
self._session_start = None
|
|
181
|
+
self._session_chars = 0
|
|
182
|
+
self._pause_count = 0
|
|
183
|
+
self._last_ks = None
|
|
184
|
+
self._streak_start = None
|
|
185
|
+
self._last_pause_s = 0.0
|
|
186
|
+
self._flow_state = "idle"
|
|
187
|
+
|
|
188
|
+
def _compute_flow(self, now: float) -> str:
|
|
189
|
+
"""Determina o flow state atual (deve ser chamado com lock)."""
|
|
190
|
+
if len(self._timestamps) < _MIN_KEYSTROKES:
|
|
191
|
+
return "idle"
|
|
192
|
+
|
|
193
|
+
cpm = self._window_cpm()
|
|
194
|
+
if cpm == 0.0:
|
|
195
|
+
return "idle"
|
|
196
|
+
wpm = cpm / _CHARS_PER_WORD
|
|
197
|
+
|
|
198
|
+
streak_s = (now - self._streak_start) if self._streak_start else 0.0
|
|
199
|
+
|
|
200
|
+
if wpm < 5:
|
|
201
|
+
return "idle"
|
|
202
|
+
if wpm < 15 or streak_s < 30:
|
|
203
|
+
return "warming"
|
|
204
|
+
if wpm >= 25 and streak_s >= 120:
|
|
205
|
+
return "deep_flow"
|
|
206
|
+
return "flow"
|
src/editor/save_hooks.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Registro de observadores de salvamento de arquivos.
|
|
2
|
+
|
|
3
|
+
Permite que painéis (ex.: navegador remoto) reajam a qualquer gravação feita
|
|
4
|
+
pelo editor - salvar, salvar tudo ou autosave - sem acoplar o editor a eles.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import logging
|
|
10
|
+
import threading
|
|
11
|
+
from collections.abc import Callable
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger("Codis.SaveHooks")
|
|
15
|
+
|
|
16
|
+
SaveObserver = Callable[[Path], None]
|
|
17
|
+
|
|
18
|
+
_lock = threading.Lock()
|
|
19
|
+
_observers: list[SaveObserver] = []
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def register(observer: SaveObserver) -> Callable[[], None]:
|
|
23
|
+
"""Registra ``observer`` e devolve uma função que o remove."""
|
|
24
|
+
with _lock:
|
|
25
|
+
_observers.append(observer)
|
|
26
|
+
|
|
27
|
+
def _unregister() -> None:
|
|
28
|
+
with _lock:
|
|
29
|
+
if observer in _observers:
|
|
30
|
+
_observers.remove(observer)
|
|
31
|
+
|
|
32
|
+
return _unregister
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def notify_saved(path: Path) -> None:
|
|
36
|
+
"""Avisa todos os observadores que ``path`` foi gravado em disco."""
|
|
37
|
+
with _lock:
|
|
38
|
+
snapshot = list(_observers)
|
|
39
|
+
for observer in snapshot:
|
|
40
|
+
try:
|
|
41
|
+
observer(path)
|
|
42
|
+
except Exception:
|
|
43
|
+
logger.exception("Observador de save falhou: %r", observer)
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
"""Codis - SmartSelection: expansão e contração de seleção semântica.
|
|
2
|
+
|
|
3
|
+
Implementa o recurso de "Expand/Shrink Selection" do VS Code:
|
|
4
|
+
- ``Alt+Shift+ -> `` expande a seleção para o próximo
|
|
5
|
+
nível semântico (palavra -> expressão -> linha -> bloco -> função -> arquivo).
|
|
6
|
+
- ``Alt+Shift+ <- `` contrai a seleção para o nível anterior.
|
|
7
|
+
|
|
8
|
+
A expansão é feita por análise de tokens e delimitadores no texto, sem
|
|
9
|
+
depender de AST (funciona em qualquer linguagem).
|
|
10
|
+
|
|
11
|
+
que a contração restaure exatamente a seleção antes da última expansão.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import contextlib
|
|
17
|
+
import logging
|
|
18
|
+
import re
|
|
19
|
+
import tkinter as tk
|
|
20
|
+
from typing import TYPE_CHECKING
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
logger = logging.getLogger("Codis")
|
|
26
|
+
|
|
27
|
+
_BLOCK_PAIRS: dict[str, str] = {
|
|
28
|
+
"(": ")",
|
|
29
|
+
"[": "]",
|
|
30
|
+
"{": "}",
|
|
31
|
+
'"': '"',
|
|
32
|
+
"'": "'",
|
|
33
|
+
"`": "`",
|
|
34
|
+
"«": "»",
|
|
35
|
+
}
|
|
36
|
+
_CLOSERS = set(_BLOCK_PAIRS.values())
|
|
37
|
+
_OPENERS = set(_BLOCK_PAIRS.keys())
|
|
38
|
+
|
|
39
|
+
_WORD_RE = re.compile(r"[\w]")
|
|
40
|
+
|
|
41
|
+
_EXPR_RE = re.compile(r"[^\s,;()[\]{}\"\'\`]")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class SmartSelection:
|
|
45
|
+
"""Gerencia expansão e contração semântica de seleção no editor.
|
|
46
|
+
|
|
47
|
+
restaure exatamente a seleção anterior à última expansão.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
txt: Widget tk.Text do editor.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
def __init__(self, txt: tk.Text) -> None:
|
|
54
|
+
self._txt = txt
|
|
55
|
+
self._history: list[tuple[str, str]] = []
|
|
56
|
+
|
|
57
|
+
def expand(self) -> None:
|
|
58
|
+
"""Expande a seleção atual para o próximo nível semântico.
|
|
59
|
+
|
|
60
|
+
Sequência de expansão:
|
|
61
|
+
1. Palavra sob o cursor
|
|
62
|
+
2. Expressão (token delimitado por espaços/operadores)
|
|
63
|
+
3. Conteúdo dentro de delimitadores (parênteses, colchetes, aspas)
|
|
64
|
+
4. Incluindo os delimitadores
|
|
65
|
+
5. Linha completa
|
|
66
|
+
6. Bloco de indentação (parágrafo)
|
|
67
|
+
7. Arquivo inteiro
|
|
68
|
+
"""
|
|
69
|
+
try:
|
|
70
|
+
cur_sel = self._get_current_selection()
|
|
71
|
+
|
|
72
|
+
if cur_sel:
|
|
73
|
+
self._history.append(cur_sel)
|
|
74
|
+
else:
|
|
75
|
+
pos = self._txt.index("insert")
|
|
76
|
+
self._history.append((pos, pos))
|
|
77
|
+
|
|
78
|
+
new_sel = self._compute_expansion(cur_sel)
|
|
79
|
+
if new_sel and new_sel != cur_sel:
|
|
80
|
+
self._apply_selection(*new_sel)
|
|
81
|
+
except tk.TclError as exc:
|
|
82
|
+
logger.debug("SmartSelection.expand error: %s", exc)
|
|
83
|
+
|
|
84
|
+
def shrink(self) -> None:
|
|
85
|
+
"""Contrai a seleção para o nível anterior (desfaz o último expand)."""
|
|
86
|
+
if not self._history:
|
|
87
|
+
return
|
|
88
|
+
prev = self._history.pop()
|
|
89
|
+
try:
|
|
90
|
+
self._apply_selection(*prev)
|
|
91
|
+
except tk.TclError as exc:
|
|
92
|
+
logger.debug("SmartSelection.shrink error: %s", exc)
|
|
93
|
+
|
|
94
|
+
def reset_history(self) -> None:
|
|
95
|
+
"""Reinicia o histórico de seleção semântica ao estado inicial."""
|
|
96
|
+
self._history.clear()
|
|
97
|
+
|
|
98
|
+
def _compute_expansion(
|
|
99
|
+
self, current: tuple[str, str] | None
|
|
100
|
+
) -> tuple[str, str] | None:
|
|
101
|
+
"""Calcula a próxima expansão a partir da seleção corrente.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
current: Tupla (start_idx, end_idx) da seleção atual, ou None.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
tuple[str, str] | None: Nova seleção expandida ou None se já é máxima.
|
|
108
|
+
"""
|
|
109
|
+
if not current or current[0] == current[1]:
|
|
110
|
+
return self._select_word()
|
|
111
|
+
|
|
112
|
+
start, end = current
|
|
113
|
+
|
|
114
|
+
for fn in (
|
|
115
|
+
self._expand_to_expression,
|
|
116
|
+
self._expand_to_inner_block,
|
|
117
|
+
self._expand_to_outer_block,
|
|
118
|
+
self._expand_to_line,
|
|
119
|
+
self._expand_to_paragraph,
|
|
120
|
+
self._expand_to_all,
|
|
121
|
+
):
|
|
122
|
+
result = fn(start, end)
|
|
123
|
+
if result and result != current:
|
|
124
|
+
return result
|
|
125
|
+
|
|
126
|
+
return None
|
|
127
|
+
|
|
128
|
+
def _select_word(self) -> tuple[str, str] | None:
|
|
129
|
+
"""Seleciona a palavra inteira sob o cursor.
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
tuple[str, str] | None: Índices de início e fim da palavra.
|
|
133
|
+
"""
|
|
134
|
+
try:
|
|
135
|
+
idx = self._txt.index("insert")
|
|
136
|
+
line_num, col = map(int, idx.split("."))
|
|
137
|
+
line_text = self._txt.get(f"{line_num}.0", f"{line_num}.end")
|
|
138
|
+
if not line_text or col >= len(line_text):
|
|
139
|
+
return (idx, idx)
|
|
140
|
+
|
|
141
|
+
char = line_text[col]
|
|
142
|
+
if not _WORD_RE.match(char):
|
|
143
|
+
if col > 0 and _WORD_RE.match(line_text[col - 1]):
|
|
144
|
+
col -= 1
|
|
145
|
+
else:
|
|
146
|
+
return (idx, idx)
|
|
147
|
+
|
|
148
|
+
start = col
|
|
149
|
+
while start > 0 and _WORD_RE.match(line_text[start - 1]):
|
|
150
|
+
start -= 1
|
|
151
|
+
|
|
152
|
+
end = col + 1
|
|
153
|
+
while end < len(line_text) and _WORD_RE.match(line_text[end]):
|
|
154
|
+
end += 1
|
|
155
|
+
|
|
156
|
+
return (f"{line_num}.{start}", f"{line_num}.{end}")
|
|
157
|
+
except (tk.TclError, ValueError):
|
|
158
|
+
return None
|
|
159
|
+
|
|
160
|
+
def _expand_to_expression(self, start: str, end: str) -> tuple[str, str] | None:
|
|
161
|
+
"""Expande a seleção para incluir a expressão completa (token).
|
|
162
|
+
|
|
163
|
+
Args:
|
|
164
|
+
start: Índice Tkinter do início da seleção.
|
|
165
|
+
end: Índice Tkinter do fim da seleção.
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
tuple[str, str] | None: Seleção expandida ou None.
|
|
169
|
+
"""
|
|
170
|
+
try:
|
|
171
|
+
sline, scol = map(int, start.split("."))
|
|
172
|
+
eline, ecol = map(int, end.split("."))
|
|
173
|
+
if sline != eline:
|
|
174
|
+
return None
|
|
175
|
+
line_text = self._txt.get(f"{sline}.0", f"{sline}.end")
|
|
176
|
+
if not line_text:
|
|
177
|
+
return None
|
|
178
|
+
|
|
179
|
+
new_start = scol
|
|
180
|
+
while new_start > 0 and _EXPR_RE.match(line_text[new_start - 1]):
|
|
181
|
+
new_start -= 1
|
|
182
|
+
|
|
183
|
+
new_end = ecol
|
|
184
|
+
while new_end < len(line_text) and _EXPR_RE.match(line_text[new_end]):
|
|
185
|
+
new_end += 1
|
|
186
|
+
|
|
187
|
+
new = (f"{sline}.{new_start}", f"{sline}.{new_end}")
|
|
188
|
+
return new if new != (start, end) else None
|
|
189
|
+
except (tk.TclError, ValueError):
|
|
190
|
+
return None
|
|
191
|
+
|
|
192
|
+
def _expand_to_inner_block(self, start: str, end: str) -> tuple[str, str] | None:
|
|
193
|
+
"""Expande para o conteúdo interno do bloco delimitador mais próximo.
|
|
194
|
+
|
|
195
|
+
Args:
|
|
196
|
+
start: Índice Tkinter do início da seleção.
|
|
197
|
+
end: Índice Tkinter do fim da seleção.
|
|
198
|
+
|
|
199
|
+
Returns:
|
|
200
|
+
tuple[str, str] | None: Seleção expandida incluindo apenas conteúdo.
|
|
201
|
+
"""
|
|
202
|
+
try:
|
|
203
|
+
content = self._txt.get("1.0", "end-1c")
|
|
204
|
+
start_flat = self._idx_to_flat(start, content)
|
|
205
|
+
end_flat = self._idx_to_flat(end, content)
|
|
206
|
+
|
|
207
|
+
open_pos, close_pos, _ = (
|
|
208
|
+
self._find_enclosing_block( # pylint: disable=no-value-for-parameter
|
|
209
|
+
content, start_flat, end_flat
|
|
210
|
+
)
|
|
211
|
+
)
|
|
212
|
+
if open_pos is None:
|
|
213
|
+
return None
|
|
214
|
+
|
|
215
|
+
new_start = self._flat_to_idx(open_pos + 1, content)
|
|
216
|
+
new_end = self._flat_to_idx(close_pos, content)
|
|
217
|
+
new = (new_start, new_end)
|
|
218
|
+
return new if new != (start, end) else None
|
|
219
|
+
except (tk.TclError, ValueError):
|
|
220
|
+
return None
|
|
221
|
+
|
|
222
|
+
def _expand_to_outer_block(self, start: str, end: str) -> tuple[str, str] | None:
|
|
223
|
+
"""Expande para incluir os próprios delimitadores do bloco.
|
|
224
|
+
|
|
225
|
+
Args:
|
|
226
|
+
start: Índice Tkinter do início da seleção.
|
|
227
|
+
end: Índice Tkinter do fim da seleção.
|
|
228
|
+
|
|
229
|
+
Returns:
|
|
230
|
+
tuple[str, str] | None: Seleção expandida incluindo delimitadores.
|
|
231
|
+
"""
|
|
232
|
+
try:
|
|
233
|
+
content = self._txt.get("1.0", "end-1c")
|
|
234
|
+
start_flat = self._idx_to_flat(start, content)
|
|
235
|
+
end_flat = self._idx_to_flat(end, content)
|
|
236
|
+
|
|
237
|
+
open_pos, close_pos, _ = (
|
|
238
|
+
self._find_enclosing_block( # pylint: disable=no-value-for-parameter
|
|
239
|
+
content, start_flat, end_flat
|
|
240
|
+
)
|
|
241
|
+
)
|
|
242
|
+
if open_pos is None:
|
|
243
|
+
return None
|
|
244
|
+
|
|
245
|
+
new_start = self._flat_to_idx(open_pos, content)
|
|
246
|
+
new_end = self._flat_to_idx(close_pos + 1, content)
|
|
247
|
+
new = (new_start, new_end)
|
|
248
|
+
return new if new != (start, end) else None
|
|
249
|
+
except (tk.TclError, ValueError):
|
|
250
|
+
return None
|
|
251
|
+
|
|
252
|
+
def _expand_to_line( # pylint: disable=bad-staticmethod-argument
|
|
253
|
+
self, start: str, end: str
|
|
254
|
+
) -> tuple[str, str] | None:
|
|
255
|
+
"""Expande a seleção para a(s) linha(s) completa(s).
|
|
256
|
+
|
|
257
|
+
Args:
|
|
258
|
+
start: Índice Tkinter do início da seleção.
|
|
259
|
+
end: Índice Tkinter do fim da seleção.
|
|
260
|
+
|
|
261
|
+
Returns:
|
|
262
|
+
tuple[str, str] | None: Seleção cobrindo as linhas completas.
|
|
263
|
+
"""
|
|
264
|
+
try:
|
|
265
|
+
sline = int(start.split(".")[0])
|
|
266
|
+
eline = int(end.split(".")[0])
|
|
267
|
+
new = (f"{sline}.0", f"{eline}.end")
|
|
268
|
+
return new if new != (start, end) else None
|
|
269
|
+
except ValueError:
|
|
270
|
+
return None
|
|
271
|
+
|
|
272
|
+
def _expand_to_paragraph(self, start: str, end: str) -> tuple[str, str] | None:
|
|
273
|
+
"""Expande para o bloco de indentação (parágrafo semântico).
|
|
274
|
+
|
|
275
|
+
Encontra as linhas vizinhas com indentação maior ou igual à linha
|
|
276
|
+
de início para definir o bloco.
|
|
277
|
+
|
|
278
|
+
Args:
|
|
279
|
+
start: Índice Tkinter do início da seleção.
|
|
280
|
+
end: Índice Tkinter do fim da seleção.
|
|
281
|
+
|
|
282
|
+
Returns:
|
|
283
|
+
tuple[str, str] | None: Seleção cobrindo o bloco de indentação.
|
|
284
|
+
"""
|
|
285
|
+
try:
|
|
286
|
+
sline = int(start.split(".")[0])
|
|
287
|
+
eline = int(end.split(".")[0])
|
|
288
|
+
|
|
289
|
+
ref_text = self._txt.get(f"{sline}.0", f"{sline}.end")
|
|
290
|
+
ref_indent = len(ref_text) - len(ref_text.lstrip())
|
|
291
|
+
|
|
292
|
+
new_sline = sline
|
|
293
|
+
total = int(self._txt.index("end").split(".")[0])
|
|
294
|
+
line = sline - 1
|
|
295
|
+
while line >= 1:
|
|
296
|
+
raw = self._txt.get(f"{line}.0", f"{line}.end")
|
|
297
|
+
if not raw.strip():
|
|
298
|
+
break
|
|
299
|
+
indent = len(raw) - len(raw.lstrip())
|
|
300
|
+
if indent < ref_indent:
|
|
301
|
+
break
|
|
302
|
+
new_sline = line
|
|
303
|
+
line -= 1
|
|
304
|
+
|
|
305
|
+
new_eline = eline
|
|
306
|
+
line = eline + 1
|
|
307
|
+
while line <= total:
|
|
308
|
+
raw = self._txt.get(f"{line}.0", f"{line}.end")
|
|
309
|
+
if not raw.strip():
|
|
310
|
+
break
|
|
311
|
+
indent = len(raw) - len(raw.lstrip())
|
|
312
|
+
if indent < ref_indent:
|
|
313
|
+
break
|
|
314
|
+
new_eline = line
|
|
315
|
+
line += 1
|
|
316
|
+
|
|
317
|
+
new = (f"{new_sline}.0", f"{new_eline}.end")
|
|
318
|
+
return new if new != (start, end) else None
|
|
319
|
+
except (tk.TclError, ValueError):
|
|
320
|
+
return None
|
|
321
|
+
|
|
322
|
+
def _expand_to_all(self, start: str, end: str) -> tuple[str, str] | None:
|
|
323
|
+
"""Expande para o arquivo inteiro; ``start`` e ``end`` não são usados."""
|
|
324
|
+
_ = start, end
|
|
325
|
+
try:
|
|
326
|
+
new = ("1.0", self._txt.index("end-1c"))
|
|
327
|
+
return new
|
|
328
|
+
except tk.TclError:
|
|
329
|
+
return None
|
|
330
|
+
|
|
331
|
+
def _find_enclosing_block( # pylint: disable=bad-staticmethod-argument
|
|
332
|
+
self,
|
|
333
|
+
content: str,
|
|
334
|
+
start_flat: int,
|
|
335
|
+
end_flat: int,
|
|
336
|
+
) -> tuple[int | None, int | None, str | None]:
|
|
337
|
+
"""Encontra o par de delimitadores que envolve a seleção.
|
|
338
|
+
|
|
339
|
+
Args:
|
|
340
|
+
content: Conteúdo completo do documento como string plana.
|
|
341
|
+
start_flat: Posição plana do início da seleção.
|
|
342
|
+
end_flat: Posição plana do fim da seleção.
|
|
343
|
+
|
|
344
|
+
Returns:
|
|
345
|
+
tuple: (posição_abertura, posição_fechamento, char_opener) ou (None, None, None).
|
|
346
|
+
"""
|
|
347
|
+
|
|
348
|
+
for pos in range(start_flat - 1, -1, -1):
|
|
349
|
+
ch = content[pos]
|
|
350
|
+
if ch in _OPENERS:
|
|
351
|
+
closer = _BLOCK_PAIRS[ch]
|
|
352
|
+
|
|
353
|
+
depth = 1
|
|
354
|
+
for fpos in range(pos + 1, len(content)):
|
|
355
|
+
fc = content[fpos]
|
|
356
|
+
if fc == ch and ch not in ('"', "'", "`"):
|
|
357
|
+
depth += 1
|
|
358
|
+
elif fc == closer:
|
|
359
|
+
depth -= 1
|
|
360
|
+
if depth == 0:
|
|
361
|
+
if fpos >= end_flat:
|
|
362
|
+
return (pos, fpos, ch)
|
|
363
|
+
break
|
|
364
|
+
|
|
365
|
+
return (None, None, None)
|
|
366
|
+
|
|
367
|
+
@staticmethod
|
|
368
|
+
def _idx_to_flat(idx: str, content: str) -> int:
|
|
369
|
+
"""Converte índice Tkinter (line.col) para posição plana na string.
|
|
370
|
+
|
|
371
|
+
Args:
|
|
372
|
+
idx: Índice no formato 'linha.coluna'.
|
|
373
|
+
content: Conteúdo completo do documento.
|
|
374
|
+
|
|
375
|
+
Returns:
|
|
376
|
+
int: Posição plana (0-based) na string de conteúdo.
|
|
377
|
+
"""
|
|
378
|
+
line, col = map(int, idx.split("."))
|
|
379
|
+
lines = content.splitlines(keepends=True)
|
|
380
|
+
flat = sum(len(l_) for l_ in lines[: line - 1])
|
|
381
|
+
return flat + col
|
|
382
|
+
|
|
383
|
+
@staticmethod
|
|
384
|
+
def _flat_to_idx(flat: int, content: str) -> str:
|
|
385
|
+
"""Converte posição plana para índice Tkinter (line.col).
|
|
386
|
+
|
|
387
|
+
Args:
|
|
388
|
+
flat: Posição plana (0-based) na string de conteúdo.
|
|
389
|
+
content: Conteúdo completo do documento.
|
|
390
|
+
|
|
391
|
+
Returns:
|
|
392
|
+
str: Índice no formato 'linha.coluna'.
|
|
393
|
+
"""
|
|
394
|
+
lines = content.splitlines(keepends=True)
|
|
395
|
+
pos = 0
|
|
396
|
+
for i, line in enumerate(lines):
|
|
397
|
+
if pos + len(line) > flat:
|
|
398
|
+
return f"{i + 1}.{flat - pos}"
|
|
399
|
+
pos += len(line)
|
|
400
|
+
|
|
401
|
+
return f"{len(lines)}.{flat - pos}"
|
|
402
|
+
|
|
403
|
+
def _get_current_selection(self) -> tuple[str, str] | None:
|
|
404
|
+
"""Retorna a seleção atual do editor, ou None se não há seleção.
|
|
405
|
+
|
|
406
|
+
Returns:
|
|
407
|
+
tuple[str, str] | None: Tupla (start_idx, end_idx) ou None.
|
|
408
|
+
"""
|
|
409
|
+
with contextlib.suppress(tk.TclError):
|
|
410
|
+
sel = self._txt.tag_ranges("sel")
|
|
411
|
+
if sel:
|
|
412
|
+
return (str(sel[0]), str(sel[1]))
|
|
413
|
+
return None
|
|
414
|
+
|
|
415
|
+
def _apply_selection(self, start: str, end: str) -> None:
|
|
416
|
+
"""Aplica uma seleção no editor.
|
|
417
|
+
|
|
418
|
+
Args:
|
|
419
|
+
start: Índice Tkinter do início da seleção.
|
|
420
|
+
end: Índice Tkinter do fim da seleção.
|
|
421
|
+
"""
|
|
422
|
+
self._txt.tag_remove("sel", "1.0", "end")
|
|
423
|
+
self._txt.tag_add("sel", start, end)
|
|
424
|
+
self._txt.mark_set("insert", end)
|
|
425
|
+
self._txt.see(start)
|