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
0 commit comments