The editor now has context aware completions
This commit is contained in:
parent
1a1bbd0838
commit
960967c8a6
18 changed files with 1984 additions and 0 deletions
40
pglab/codeeditor/CompletionPopup.h
Normal file
40
pglab/codeeditor/CompletionPopup.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef COMPLETIONPOPUP_H
|
||||
#define COMPLETIONPOPUP_H
|
||||
|
||||
#include <QListWidget>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
struct EditorCompletionItem {
|
||||
QString display;
|
||||
QString detail;
|
||||
QString insertText;
|
||||
bool ambiguous = false;
|
||||
};
|
||||
|
||||
struct EditorCompletionResult {
|
||||
int replaceStart = 0;
|
||||
int replaceLen = 0;
|
||||
bool hasQualifier = false; // completing behind "name."
|
||||
std::vector<EditorCompletionItem> items;
|
||||
};
|
||||
|
||||
/// Callback that determines the completions for a cursor position in the text
|
||||
using EditorCompletionCallback = std::function<EditorCompletionResult(const QString &text, int cursorPos)>;
|
||||
|
||||
/// List shown below the cursor, it never takes keyboard focus so typing continues in the editor.
|
||||
class CompletionPopup : public QListWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CompletionPopup(QWidget *parent);
|
||||
|
||||
void setItems(const std::vector<EditorCompletionItem> &items);
|
||||
void moveSelection(int delta);
|
||||
int currentRow() const { return QListWidget::currentRow(); }
|
||||
void showAt(const QPoint &globalPos);
|
||||
|
||||
signals:
|
||||
void itemAccepted(int row);
|
||||
};
|
||||
|
||||
#endif // COMPLETIONPOPUP_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue