Skip to content

Commit 23104a6

Browse files
committed
Removed AbstractCodeHandler in favour of direct calls to the CodeHandler.
1 parent 8931823 commit 23104a6

File tree

14 files changed

+140
-233
lines changed

14 files changed

+140
-233
lines changed

lib/lveditor/include/live/abstractcodehandler.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/lveditor/include/lveditorheaders.pri

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ HEADERS += \
88
$$PWD/live/projectdocument.h \
99
$$PWD/live/codecompletionmodel.h \
1010
$$PWD/live/codecompletionsuggestion.h \
11-
$$PWD/live/abstractcodehandler.h \
1211
$$PWD/live/editorsettings.h \
1312
$$PWD/live/documenthandler.h \
1413
$$PWD/live/editorsettingscategory.h \

lib/lveditor/src/abstractcodehandler.cpp

Lines changed: 0 additions & 48 deletions
This file was deleted.

lib/lveditor/src/abstractcodehandler.h

Lines changed: 0 additions & 54 deletions
This file was deleted.

lib/lveditor/src/documenthandler.cpp

Lines changed: 13 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848
* \class lv::DocumentHandler
4949
* \brief Complements TextEdit in handling documents.
5050
*
51-
* Forwards everything to the highlighter, has a completion model in case there's a specific code handler attached to it,
52-
* it can auto-complete code, which is all behavior inherited from the AbstractCodeHandler.
51+
* Offers infrastructure for code completion, highlighting and other language specifics.
5352
*
5453
* \ingroup lveditor
5554
*/
@@ -101,6 +100,14 @@ void DocumentHandler::setTextEdit(TextEdit *te){
101100
}
102101
}
103102

103+
int DocumentHandler::currentCursorPosition() const{
104+
return m_textEdit->cursorPosition();
105+
}
106+
107+
const QChar &DocumentHandler::lastAddedChar() const{
108+
return m_lastChar;
109+
}
110+
104111

105112
/**
106113
* \fn lv::DocumentHandler::classBegin
@@ -188,17 +195,15 @@ void DocumentHandler::findCodeHandler(){
188195
WorkspaceExtension* le = it.value();
189196
if ( le->hasLanguageInterceptor() ){
190197
QObject* o = le->callLanguageInterceptor(interceptorArgs);
191-
192-
AbstractCodeHandler* ach = qobject_cast<AbstractCodeHandler*>(o);
193-
if ( ach ){
198+
if ( o ){
194199
vlog("editor-documenthandler").v() << "Found in extension: " << le->name();
195200

196-
QQmlEngine::setObjectOwnership(ach, QQmlEngine::CppOwnership);
197-
m_codeHandler = ach;
201+
QQmlEngine::setObjectOwnership(o, QQmlEngine::CppOwnership);
202+
m_codeHandler = o;
198203

199204
QList<int> features;
200205
QMetaObject::invokeMethod(
201-
ach, "languageFeatures", Qt::DirectConnection, Q_RETURN_ARG(QList<int>, features)
206+
o, "languageFeatures", Qt::DirectConnection, Q_RETURN_ARG(QList<int>, features)
202207
);
203208

204209
for ( int feature : features ){
@@ -249,33 +254,6 @@ void DocumentHandler::documentContentsChanged(int position, int, int charsAdded)
249254
}
250255
}
251256

252-
/**
253-
* \brief Slot reacting to cursor position change
254-
*
255-
* Potentially triggers the assisted completion
256-
*/
257-
void DocumentHandler::cursorWritePositionChanged(QTextCursor cursor){
258-
if ( m_codeHandler && m_editorFocus && cursor.position() == m_textEdit->cursorPosition() &&
259-
!m_projectDocument->editingStateIs(ProjectDocument::Assisted) &&
260-
!m_projectDocument->editingStateIs(ProjectDocument::Silent)
261-
)
262-
{
263-
m_projectDocument->addEditingState(ProjectDocument::Assisted);
264-
QTextCursor newCursor;
265-
m_codeHandler->assistCompletion(
266-
cursor,
267-
m_lastChar,
268-
false,
269-
m_completionModel,
270-
newCursor
271-
);
272-
m_projectDocument->removeEditingState(ProjectDocument::Assisted);
273-
if ( !newCursor.isNull() ){
274-
emit cursorPositionRequest(newCursor.position());
275-
}
276-
}
277-
}
278-
279257
/**
280258
* \brief Document that the document handler is operating on
281259
*
@@ -292,11 +270,6 @@ void DocumentHandler::setDocument(ProjectDocument *document, QJSValue){
292270
if (m_projectDocument) {
293271
m_targetDoc = m_projectDocument->textDocument();
294272

295-
connect(
296-
m_targetDoc, SIGNAL(cursorPositionChanged(QTextCursor)),
297-
this, SLOT(cursorWritePositionChanged(QTextCursor))
298-
);
299-
300273
if (m_textEdit) {
301274
m_textEdit->setTextDocument(m_targetDoc);
302275
}
@@ -318,25 +291,6 @@ void DocumentHandler::setDocument(ProjectDocument *document, QJSValue){
318291
findCodeHandler();
319292
}
320293

321-
/**
322-
* \brief Generates code completion at a given cursor position
323-
*/
324-
void DocumentHandler::generateCompletion(int cursorPosition){
325-
if ( m_targetDoc && m_codeHandler ){
326-
m_lastChar = QChar();
327-
QTextCursor cursor(m_targetDoc);
328-
cursor.setPosition(cursorPosition);
329-
QTextCursor newCursor;
330-
m_codeHandler->assistCompletion(
331-
cursor,
332-
m_lastChar,
333-
true,
334-
m_completionModel,
335-
newCursor
336-
);
337-
}
338-
}
339-
340294
/**
341295
* \brief Used to manage indentation of selected text
342296
*
@@ -378,20 +332,4 @@ bool DocumentHandler::has(int feature){
378332
return m_languageFeatures.contains(feature);
379333
}
380334

381-
/**
382-
* \brief Finds the boundaries of the code block containing the cursor position
383-
*
384-
* Mostly used for fragments
385-
*/
386-
QJSValue DocumentHandler::contextBlockRange(int cursorPosition){
387-
if ( !m_codeHandler || !m_engine )
388-
return QJSValue();
389-
390-
QPair<int, int> v = m_codeHandler->contextBlock(cursorPosition);
391-
QJSValue ob = m_engine->engine()->newObject();
392-
ob.setProperty("start", m_targetDoc->findBlock(v.first).blockNumber());
393-
ob.setProperty("end", m_targetDoc->findBlock(v.second).blockNumber());
394-
return ob;
395-
}
396-
397335
}// namespace

lib/lveditor/src/documenthandler.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "live/projectdocument.h"
2727
#include "live/lveditorglobal.h"
2828
#include "live/codecompletionmodel.h"
29-
#include "live/abstractcodehandler.h"
3029

3130
namespace lv{
3231

@@ -40,7 +39,7 @@ class LV_EDITOR_EXPORT DocumentHandler : public QObject, public QQmlParserStatus
4039
Q_OBJECT
4140
Q_INTERFACES(QQmlParserStatus)
4241
Q_PROPERTY(lv::CodeCompletionModel* completionModel READ completionModel CONSTANT)
43-
Q_PROPERTY(lv::AbstractCodeHandler* codeHandler READ codeHandler NOTIFY codeHandlerChanged)
42+
Q_PROPERTY(QObject* codeHandler READ codeHandler NOTIFY codeHandlerChanged)
4443
Q_PROPERTY(bool editorFocus READ editorFocus WRITE setEditorFocus NOTIFY editorFocusChanged)
4544
Q_ENUMS(LanguageFeatures)
4645

@@ -84,6 +83,10 @@ class LV_EDITOR_EXPORT DocumentHandler : public QObject, public QQmlParserStatus
8483
TextEdit* textEdit();
8584
void setTextEdit(TextEdit* te);
8685

86+
int currentCursorPosition() const;
87+
88+
const QChar& lastAddedChar() const;
89+
8790
/**
8891
* \brief Shows if the editor is in focus
8992
*/
@@ -93,7 +96,7 @@ class LV_EDITOR_EXPORT DocumentHandler : public QObject, public QQmlParserStatus
9396
/**
9497
* \brief Code handler getter
9598
*/
96-
AbstractCodeHandler* codeHandler();
99+
QObject *codeHandler();
97100

98101
void requestCursorPosition(int position);
99102

@@ -104,10 +107,7 @@ class LV_EDITOR_EXPORT DocumentHandler : public QObject, public QQmlParserStatus
104107
public slots:
105108
void insertCompletion(int from, int to, const QString& completion);
106109
void documentContentsChanged(int position, int charsRemoved, int charsAdded);
107-
void cursorWritePositionChanged(QTextCursor cursor);
108110
void setDocument(lv::ProjectDocument* document, QJSValue options = QJSValue());
109-
void generateCompletion(int cursorPosition);
110-
QJSValue contextBlockRange(int cursorPosition);
111111

112112
void manageIndent(int from, int length, bool undo = false);
113113

@@ -133,7 +133,7 @@ public slots:
133133
QChar m_lastChar;
134134
QTextDocument* m_targetDoc;
135135
CodeCompletionModel* m_completionModel;
136-
AbstractCodeHandler* m_codeHandler;
136+
QObject* m_codeHandler;
137137
ProjectDocument* m_projectDocument;
138138
int m_indentSize;
139139
QString m_indentContent;
@@ -163,6 +163,7 @@ inline TextEdit *DocumentHandler::textEdit(){
163163
return m_textEdit;
164164
}
165165

166+
/** \brief Returns true if the current editor has focus */
166167
inline bool DocumentHandler::editorFocus() const{
167168
return m_editorFocus;
168169
}
@@ -177,7 +178,7 @@ inline void DocumentHandler::setEditorFocus(bool editorFocus){
177178
emit editorFocusChanged();
178179
}
179180

180-
inline AbstractCodeHandler *DocumentHandler::codeHandler(){
181+
inline QObject *DocumentHandler::codeHandler(){
181182
return m_codeHandler;
182183
}
183184

lib/lveditor/src/lveditor.pri

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ HEADERS += \
1111
$$PWD/keymap.h \
1212
$$PWD/codecompletionmodel.h \
1313
$$PWD/codecompletionsuggestion.h \
14-
$$PWD/abstractcodehandler.h \
1514
$$PWD/projectnavigationmodel.h \
1615
$$PWD/projectdocumentmodel.h \
1716
$$PWD/editorsettings.h \
@@ -51,7 +50,6 @@ SOURCES += \
5150
$$PWD/projectdocument.cpp \
5251
$$PWD/codecompletionmodel.cpp \
5352
$$PWD/codecompletionsuggestion.cpp \
54-
$$PWD/abstractcodehandler.cpp \
5553
$$PWD/projectnavigationmodel.cpp \
5654
$$PWD/projectdocumentmodel.cpp \
5755
$$PWD/editorsettings.cpp \

0 commit comments

Comments
 (0)