Skip to content

feat: in-editor completion / autocomplete popup#157

Open
Copilot wants to merge 23 commits into
developfrom
copilot/add-editor-autocomplete-functionality
Open

feat: in-editor completion / autocomplete popup#157
Copilot wants to merge 23 commits into
developfrom
copilot/add-editor-autocomplete-functionality

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 17, 2026

  • Create IEditorCompletionProvider interface + CompletionItem record in src/Terminal.Gui.Editor/Completion/
  • Create Editor.Completion.cs partial — CompletionProvider property, popup lifecycle, key interception, caret-anchored positioning
  • Wire completion key handling in Editor.Keyboard.cs (notify provider on text input)
  • Wire trivial word-completion provider in examples/ted (WordCompletionProvider, Ctrl+Space trigger)
  • Autocomplete disabled by default; enable via Settings dialog → Config tab → Auto Complete
  • Add unit tests for completion logic (prefix extraction, accept/dismiss, undo)
  • Use Popover<ListView, CompletionItem?> for the autocomplete popup
  • Fix: Popover as visual-only overlay — Enabled = false keeps Editor focused; character keys handled directly in HandleCompletionKey; mouse clicks detected via HandleCompletionMouse in Editor.OnMouseEvent
  • Fix: Arrow key navigation updates both internal index and visible ListView selection (+ SetNeedsDraw on Popover)
  • Fix: Character key typing while popup is open inserts directly into document and refreshes completion list
  • Fix: Mouse click on completion item accepts the clicked item (hit-tests Popover screen frame)
  • Fix: Backspace while popup is open removes character and refreshes list
  • Resolve merge conflicts with origin/develop (overwrite-mode, IDesignable, kill-ring, file-io PRs)
  • All 486 unit tests + 262 integration tests pass

Copilot AI assigned Copilot and tig May 17, 2026
Copilot AI linked an issue May 17, 2026 that may be closed by this pull request
6 tasks
Copilot AI and others added 2 commits May 17, 2026 14:43
…rovider, CompletionItem, Editor.Completion.cs, WordCompletionProvider in ted)

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/dddd5eaf-c7d7-40bb-866d-9961401a391b

Co-authored-by: tig <585482+tig@users.noreply.github.com>
…decisions.md; apply jb cleanup

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/dddd5eaf-c7d7-40bb-866d-9961401a391b

Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copilot AI changed the title [WIP] Add in-editor autocomplete popup for Editor component feat: in-editor completion / autocomplete popup May 17, 2026
Copilot finished work on behalf of tig May 17, 2026 14:48
Copilot AI requested a review from tig May 17, 2026 14:48
Copy link
Copy Markdown
Member

@tig tig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot see comments.

Comment thread examples/ted/TedApp.cs Outdated
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 17, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.jetbrains.com
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2026.1.1/tools/net8.0/any/cleanupcode.unix.runtimeconfig.json /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2026.1.1/tools/net8.0/any/cleanupcode.exe Terminal.Gui.Editor.slnx --include=examples/ted/EditorSettings.cs;examples/ted/EditorSettingsDialog.cs;examples/ted/TedApp.cs (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of tig May 17, 2026 15:47
Copilot AI requested a review from tig May 17, 2026 15:47
@tig
Copy link
Copy Markdown
Member

tig commented May 17, 2026

@copilot the setting for this on Ted is supposed to be in the first tab, not the Tabs tab of the settings dialog.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 17, 2026

@copilot the setting for this on Ted is supposed to be in the first tab, not the Tabs tab of the settings dialog.

Moved the "Auto Complete (Ctrl+Space)" checkbox from the Tab Settings tab to the Config tab (first tab) in the Settings dialog. Commit 8f4d77d.

Copilot finished work on behalf of tig May 17, 2026 16:17
@tig
Copy link
Copy Markdown
Member

tig commented May 17, 2026

@copilot read Claude.md and ensure you are following it in this pr.

This comment was marked as outdated.

Copilot finished work on behalf of tig May 17, 2026 16:26
@tig
Copy link
Copy Markdown
Member

tig commented May 17, 2026

@copilot do not use popovermenu for autocompldete. It should be a DropDownList using Popover.

Ensure you are following CLAUDE.md.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 17, 2026

@copilot first, ensure you are building unit tests for these failures (that fail) before fixing:

using is in the autocomplete list
...

Added failing tests first in commit 828c17f, then fixed all three issues in commit d12c713:

  1. Popover capturing keyboard input — Set Enabled = false on the Popover after MakeVisible so it renders the list but doesn't intercept keystrokes. All key handling (Enter/Tab/arrows/Esc) is done by HandleCompletionKey in the Editor.

  2. Enter/Tab/arrows not routed to completion — Moved HandleCompletionKey from OnKeyDownNotHandled to OnKeyDown, which runs before command bindings. Previously, Enter triggered newline and Tab triggered indent because those bindings fired first.

  3. Setting CompletionProvider = null didn't dismiss — Added setter logic that calls DismissCompletion() when the provider is cleared.

All 476 unit tests + 226 integration tests pass. CodeQL clean.

Copilot finished work on behalf of tig May 17, 2026 19:44
@tig
Copy link
Copy Markdown
Member

tig commented May 17, 2026

@copilot now, when the popover is up, up/down arrow keys don't work to navigate the list.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7008d9405e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Terminal.Gui.Editor/Editor.Completion.cs
Comment thread src/Terminal.Gui.Editor/Editor.Completion.cs
…x and ListView

- Fixed arrow up/down keys updating the completion selected index correctly
- Added UpdateCompletionListSelection helper for visual ListView updates
- Added CompletionSelectedIndex internal property for test verification
- Fixed unit tests: "unsafe" doesn't start with "us" (starts with "un")
- Added ArrowDown_Wraps_To_First_Item test
- Added ArrowDown_Then_Enter_Accepts_Second_Item integration test

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/ca58f879-5dc4-433d-8e77-2c1161ff8745

Co-authored-by: tig <585482+tig@users.noreply.github.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 17, 2026

@copilot now, when the popover is up, up/down arrow keys don't work to navigate the list.

Fixed in ebdb104. Arrow up/down now correctly updates both the internal selected index and the visible ListView selection via UpdateCompletionListSelection. The arrow handler directly sets _completionSelectedIndex and updates _completionListView.SelectedItem + SetNeedsDraw().

Added tests:

  • ArrowKeys_Navigate_Completion_Selection — Down arrow moves to second item, accept inserts it
  • ArrowUp_Wraps_To_Last_Item — Up from index 0 wraps to last
  • ArrowDown_Wraps_To_First_Item — Down from last wraps to first
  • ArrowDown_Then_Enter_Accepts_Second_Item — full integration test with key injection

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copilot finished work on behalf of tig May 17, 2026 21:15
@tig
Copy link
Copy Markdown
Member

tig commented May 17, 2026

@copilot it's still not working. Plus when I click on a list item in the popover list, it dismisses without selecting the autocomplete item i clicked on.

Study how TextView does this and make sure you are not re-inventing how this should work. Yes, I know TextViewAutoComplete is a different beast, but it works and should show you the way.

We are going in circles here and I'm afraid you are now just hacking and playing whack-a-mole. do it right.

@tig
Copy link
Copy Markdown
Member

tig commented May 17, 2026

@copilot resolve the merge conflicts in this pull request

…ar insert in HandleCompletionKey, mouse click handling via Editor.OnMouseEvent

The Popover intercepts character keys internally (before KeyDown event fires),
preventing them from reaching any event handler. Navigation keys (arrows) DO
reach the KeyDown event. The solution:

1. Keep Enabled=false on the Popover (visual-only overlay, Editor retains focus)
2. HandleCompletionKey now handles character keys directly (insert + refresh)
3. HandleCompletionMouse detects clicks in the Popover's screen area
4. Arrow keys update ListView selection + SetNeedsDraw on both ListView and Popover
5. Backspace handled in HandleCompletionKey (remove char + refresh)

This follows the PopupAutocomplete pattern from TG: the host control owns all
input dispatch, the popup just renders.

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/be8ce6c1-d6d7-403d-933a-2e44aabaa22d

Co-authored-by: tig <585482+tig@users.noreply.github.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 17, 2026

@copilot it's still not working. Plus when I click on a list item in the popover list, it dismisses without selecting the autocomplete item i clicked on.

Study how TextView does th...

Rewrote the completion popup properly in 64356e4. The root cause was that TG's Popover intercepts character keys internally (before the KeyDown event fires) — they never reach any event handler. Navigation keys (arrows) do pass through. I confirmed this with diagnostic testing.

The fix follows the PopupAutocomplete.ProcessKey pattern from TG:

  1. Popover is Enabled = false — visual-only overlay, Editor retains keyboard focus
  2. HandleCompletionKey handles ALL keys when completion is active: character keys are inserted directly into the document and the list is refreshed; arrows update ListView.SelectedItem + SetNeedsDraw; Enter/Tab accept; Esc/Backspace handled too
  3. HandleCompletionMouse detects mouse clicks in the Popover's screen frame via Editor.OnMouseEvent — single-click on an item accepts the completion
  4. Arrow key visual updates now call SetNeedsDraw on both the ListView AND the Popover

All 479 unit tests + 236 integration tests pass.

Co-authored-by: tig <585482+tig@users.noreply.github.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 17, 2026

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in d76c128. Two conflicts in Editor.Commands.cs (kill-ring commands + completion-aware editing commands) and Editor.Keyboard.cs (completion key interception + kill-ring tracking in OnKeyDown) were merged to preserve both features. All 479 unit tests + 252 integration tests pass.

Copilot finished work on behalf of tig May 17, 2026 22:06
@tig
Copy link
Copy Markdown
Member

tig commented May 18, 2026

@copilot resolve the merge conflicts in this pull request

Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 18, 2026

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in c75404f. Two files had conflicts:

  1. examples/ted/TedApp.cs — merged AutoComplete setting with new Save(_configPath) signature from file-io PR
  2. specs/public-api.md — merged both completion and file-io API sections + changelog entries

All 486 unit tests + 262 integration tests pass.

Copilot finished work on behalf of tig May 18, 2026 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor: in-editor completion / autocomplete popup

2 participants