5 |
5 |
6 """ |
6 """ |
7 Module implementing the editor component of the eric IDE. |
7 Module implementing the editor component of the eric IDE. |
8 """ |
8 """ |
9 |
9 |
|
10 import collections |
|
11 import contextlib |
|
12 import difflib |
10 import os |
13 import os |
11 import re |
14 import re |
12 import difflib |
|
13 import contextlib |
|
14 |
15 |
15 import editorconfig |
16 import editorconfig |
16 |
17 |
17 from PyQt6.QtCore import ( |
18 from PyQt6.QtCore import ( |
18 pyqtSignal, pyqtSlot, Qt, QDir, QTimer, QModelIndex, QFileInfo, |
19 pyqtSignal, pyqtSlot, Qt, QDir, QTimer, QModelIndex, QFileInfo, |
41 |
42 |
42 import UI.PixmapCache |
43 import UI.PixmapCache |
43 |
44 |
44 EditorAutoCompletionListID = 1 |
45 EditorAutoCompletionListID = 1 |
45 TemplateCompletionListID = 2 |
46 TemplateCompletionListID = 2 |
|
47 ReferencesListID = 3 |
|
48 |
|
49 ReferenceItem = collections.namedtuple( |
|
50 "ReferenceItem", ["modulePath", "codeLine", "line", "column"]) |
46 |
51 |
47 |
52 |
48 class Editor(QsciScintillaCompat): |
53 class Editor(QsciScintillaCompat): |
49 """ |
54 """ |
50 Class implementing the editor component of the eric IDE. |
55 Class implementing the editor component of the eric IDE. |
5201 # New in jedi 0.16: AC of dict keys |
5207 # New in jedi 0.16: AC of dict keys |
5202 txt = txt[1:] |
5208 txt = txt[1:] |
5203 self.insert(txt) |
5209 self.insert(txt) |
5204 self.endUndoAction() |
5210 self.endUndoAction() |
5205 self.setCursorPosition(line, col + len(txt)) |
5211 self.setCursorPosition(line, col + len(txt)) |
|
5212 |
|
5213 # template completions |
5206 elif listId == TemplateCompletionListID: |
5214 elif listId == TemplateCompletionListID: |
5207 self.__applyTemplate(txt, self.getLanguage()) |
5215 self.__applyTemplate(txt, self.getLanguage()) |
|
5216 |
|
5217 # 'goto reference' completions |
|
5218 elif listId == ReferencesListID: |
|
5219 with contextlib.suppress(ValueError, IndexError): |
|
5220 index = self.__referencesList.index(txt) |
|
5221 filename, line, column = self.__referencesPositionsList(index) |
|
5222 self.__vm.openSourceFile( |
|
5223 filename, lineno=line, pos=column, addNext=True) |
|
5224 |
5208 |
5225 |
5209 def canProvideDynamicAutoCompletion(self): |
5226 def canProvideDynamicAutoCompletion(self): |
5210 """ |
5227 """ |
5211 Public method to test the dynamic auto-completion availability. |
5228 Public method to test the dynamic auto-completion availability. |
5212 |
5229 |
8526 if self.__mouseClickHandlers[key][0] == name: |
8543 if self.__mouseClickHandlers[key][0] == name: |
8527 keys.append(key) |
8544 keys.append(key) |
8528 for key in keys: |
8545 for key in keys: |
8529 del self.__mouseClickHandlers[key] |
8546 del self.__mouseClickHandlers[key] |
8530 |
8547 |
|
8548 def gotoReferenceHandler(self, referencesList): |
|
8549 """ |
|
8550 Public method to handle a list of references to perform a goto. |
|
8551 |
|
8552 @param referencesList list of references for a 'goto' action |
|
8553 @type ReferenceItem |
|
8554 """ |
|
8555 referencesList = [] |
|
8556 referencesPositionsList = [] |
|
8557 |
|
8558 for reference in referencesPositionsList: |
|
8559 if ( |
|
8560 reference.modulePath != self.fileName() and |
|
8561 self.getCursorPosition()[0] + 1 != reference.line |
|
8562 ): |
|
8563 referencesList.append( |
|
8564 "{0}\t{1}".format(reference.line, reference.codeLine)) |
|
8565 referencesPositionsList.append( |
|
8566 reference.modulePath, reference.line, reference.column) |
|
8567 |
|
8568 if referencesList: |
|
8569 self.__referencesList = referencesList |
|
8570 self.__referencesPositionsList = referencesPositionsList |
|
8571 self.showUserList(ReferencesListID, referencesList) |
|
8572 |
8531 ####################################################################### |
8573 ####################################################################### |
8532 ## Methods implementing a Shell interface |
8574 ## Methods implementing a Shell interface |
8533 ####################################################################### |
8575 ####################################################################### |
8534 |
8576 |
8535 def __executeSelection(self): |
8577 def __executeSelection(self): |