NotepadNext icon indicating copy to clipboard operation
NotepadNext copied to clipboard

Add language keyword candidates to auto-completion

Open saberoueslati opened this issue 6 months ago • 2 comments

Description

Fixes #839

NotepadNext's auto-completion only suggests words already present in the document. This PR adds language keyword candidates to the completion list so keywords appear as suggestions even before they have been typed in the file. The change is gated by the existing Auto Completion preference and requires no new settings.


Changes

src/ScintillaNext.h

  • Added #include <QStringList> and a public QStringList languageKeywords member to hold the active language's keyword list alongside the existing languageName and languageSingleLineComment fields.

src/scripts/init.lua

  • Added GetLanguageKeywords(languageName) helper that reads languages[languageName].keywords, splits each space-separated keyword string into individual tokens, deduplicates them, recurses into additionalLanguages (matching SetLanguage's behaviour), and returns a sorted array. Returns {} for languages with no keyword definitions (e.g. plain Text).

src/NotepadNextApplication.cpp

  • Added one line at the end of setEditorLanguage() — calls GetLanguageKeywords(languageName) through the Lua state and stores the result in editor->languageKeywords. The field is unconditionally reassigned on every language change, so switching to Text or any other keyword-less language clears it automatically.

src/decorators/AutoCompletion.cpp

  • Extended showAutoCompletion() to iterate editor->languageKeywords after the document scan, inserting any keyword that starts with the current prefix into the existing QSet<QByteArray> candidate set. Deduplication is handled for free by the set. The 3-character minimum, SCFIND_MATCHCASE case-sensitivity, SC_ORDER_PERFORMSORT ordering, and the single Editor/AutoCompletion preference toggle are all preserved.

Video of manual test below :

Screencast from 2026-06-02 21-34-24.webm

saberoueslati avatar Jun 02 '26 20:06 saberoueslati

@dail8859 I'll take care of it, I'll ping you as soon as I'm finished with it.

saberoueslati avatar Jun 09 '26 00:06 saberoueslati

@dail8859 I made the changes as you requested

saberoueslati avatar Jun 09 '26 22:06 saberoueslati

Apologies for the delay. Thanks for the PR!

dail8859 avatar Jul 03 '26 18:07 dail8859