155 r"""^\|\|\|\|\|\|\| .*?$""", |
155 r"""^\|\|\|\|\|\|\| .*?$""", |
156 r"""^=======.*?$""", |
156 r"""^=======.*?$""", |
157 r"""^>>>>>>> .*?$""", |
157 r"""^>>>>>>> .*?$""", |
158 ) |
158 ) |
159 |
159 |
|
160 EncloseChars = { |
|
161 '"': '"', |
|
162 "'": "'", |
|
163 "(": "()", |
|
164 ")": "()", |
|
165 "{": "{}", # __IGNORE_WARNING_M613__ |
|
166 "}": "{}", # __IGNORE_WARNING_M613__ |
|
167 "[": "[]", |
|
168 "]": "[]", |
|
169 "<": "<>", |
|
170 ">": "<>", |
|
171 } |
|
172 |
160 def __init__(self, dbs, fn="", vm=None, |
173 def __init__(self, dbs, fn="", vm=None, |
161 filetype="", editor=None, tv=None): |
174 filetype="", editor=None, tv=None): |
162 """ |
175 """ |
163 Constructor |
176 Constructor |
164 |
177 |
6936 Protected method to handle the user input a key at a time. |
6949 Protected method to handle the user input a key at a time. |
6937 |
6950 |
6938 @param ev key event |
6951 @param ev key event |
6939 @type QKeyEvent |
6952 @type QKeyEvent |
6940 """ |
6953 """ |
|
6954 def encloseSelectedText(encString): |
|
6955 """ |
|
6956 Local function to enclose the current selection with some |
|
6957 characters. |
|
6958 |
|
6959 @param encString string to use to enclose the selection |
|
6960 (one or two characters) |
|
6961 @type str |
|
6962 """ |
|
6963 startChar = encString[0] |
|
6964 if len(encString) == 2: |
|
6965 endChar = encString[1] |
|
6966 else: |
|
6967 endChar = startChar |
|
6968 |
|
6969 sline, sindex, eline, eindex = self.getSelection() |
|
6970 replaceText = startChar + self.selectedText() + endChar |
|
6971 self.beginUndoAction() |
|
6972 self.replaceSelectedText(replaceText) |
|
6973 self.endUndoAction() |
|
6974 self.setSelection(sline, sindex + 1, eline, eindex + 1) |
|
6975 |
6941 txt = ev.text() |
6976 txt = ev.text() |
6942 |
6977 |
6943 # See it is text to insert. |
6978 # See it is text to insert. |
6944 if len(txt) and txt >= " ": |
6979 if len(txt) and txt >= " ": |
6945 if txt in ('"', "'") and self.hasSelectedText(): |
6980 if self.hasSelectedText(): |
6946 sline, sindex, eline, eindex = self.getSelection() |
6981 if txt in Editor.EncloseChars: |
6947 replaceText = txt + self.selectedText() + txt |
6982 encloseSelectedText(Editor.EncloseChars[txt]) |
6948 self.beginUndoAction() |
6983 ev.accept() |
6949 self.replaceSelectedText(replaceText) |
6984 return |
6950 self.endUndoAction() |
|
6951 self.setSelection(sline, sindex + 1, eline, eindex + 1) |
|
6952 ev.accept() |
|
6953 return |
|
6954 |
6985 |
6955 super(Editor, self).keyPressEvent(ev) |
6986 super(Editor, self).keyPressEvent(ev) |
6956 else: |
6987 else: |
6957 ev.ignore() |
6988 ev.ignore() |
6958 |
6989 |