QScintilla/Shell.py

changeset 5712
f0d08bdeacf4
parent 5711
50b6867ffcd3
child 5730
6422afc7adc4
child 5736
000ea446ff4b
equal deleted inserted replaced
5711:50b6867ffcd3 5712:f0d08bdeacf4
295 QsciScintilla.SCI_CHARRIGHT: self.__QScintillaCharRight, 295 QsciScintilla.SCI_CHARRIGHT: self.__QScintillaCharRight,
296 QsciScintilla.SCI_WORDLEFT: self.__QScintillaWordLeft, 296 QsciScintilla.SCI_WORDLEFT: self.__QScintillaWordLeft,
297 QsciScintilla.SCI_WORDRIGHT: self.__QScintillaWordRight, 297 QsciScintilla.SCI_WORDRIGHT: self.__QScintillaWordRight,
298 QsciScintilla.SCI_VCHOME: self.__QScintillaVCHome, 298 QsciScintilla.SCI_VCHOME: self.__QScintillaVCHome,
299 QsciScintilla.SCI_LINEEND: self.__QScintillaLineEnd, 299 QsciScintilla.SCI_LINEEND: self.__QScintillaLineEnd,
300 QsciScintilla.SCI_LINEUP: self.__QScintillaLineUp, 300 QsciScintilla.SCI_LINEUP: self.__QScintillaCommand,
301 QsciScintilla.SCI_LINEDOWN: self.__QScintillaLineDown, 301 QsciScintilla.SCI_LINEDOWN: self.__QScintillaCommand,
302 QsciScintilla.SCI_LINESCROLLUP: self.__QScintillaHistoryUp,
303 QsciScintilla.SCI_LINESCROLLDOWN: self.__QScintillaHistoryDown,
302 304
303 QsciScintilla.SCI_PAGEUP: self.__QScintillaAutoCompletionCommand, 305 QsciScintilla.SCI_PAGEUP: self.__QScintillaAutoCompletionCommand,
304 QsciScintilla.SCI_PAGEDOWN: self.__QScintillaAutoCompletionCommand, 306 QsciScintilla.SCI_PAGEDOWN: self.__QScintillaAutoCompletionCommand,
305 QsciScintilla.SCI_CANCEL: self.__QScintillaAutoCompletionCommand, 307 QsciScintilla.SCI_CANCEL: self.__QScintillaAutoCompletionCommand,
306 308
703 def __writePrompt(self): 705 def __writePrompt(self):
704 """ 706 """
705 Private method to write the prompt. 707 Private method to write the prompt.
706 """ 708 """
707 self.__write(self.inContinue and sys.ps2 or sys.ps1) 709 self.__write(self.inContinue and sys.ps2 or sys.ps1)
710 # little trick to get the cursor position registered within QScintilla
711 self.SendScintilla(QsciScintilla.SCI_CHARLEFT)
712 self.SendScintilla(QsciScintilla.SCI_CHARRIGHT)
708 713
709 def __clientStatement(self, more): 714 def __clientStatement(self, more):
710 """ 715 """
711 Private method to handle the response from the debugger client. 716 Private method to handle the response from the debugger client.
712 717
1089 else: 1094 else:
1090 self.__insertTextNoEcho(txt) 1095 self.__insertTextNoEcho(txt)
1091 else: 1096 else:
1092 ev.ignore() 1097 ev.ignore()
1093 1098
1099 def __QScintillaCommand(self, cmd):
1100 """
1101 Private method to send the command to QScintilla.
1102
1103 @param cmd QScintilla command
1104 """
1105 self.SendScintilla(cmd)
1106
1094 def __QScintillaTab(self, cmd): 1107 def __QScintillaTab(self, cmd):
1095 """ 1108 """
1096 Private method to handle the Tab key. 1109 Private method to handle the Tab key.
1097 1110
1098 @param cmd QScintilla command 1111 @param cmd QScintilla command
1208 buf = buf.replace(sys.ps1, "") 1221 buf = buf.replace(sys.ps1, "")
1209 if buf.startswith(sys.ps2): 1222 if buf.startswith(sys.ps2):
1210 buf = buf.replace(sys.ps2, "") 1223 buf = buf.replace(sys.ps2, "")
1211 self.insert('\n') 1224 self.insert('\n')
1212 self.__executeCommand(buf) 1225 self.__executeCommand(buf)
1226 else:
1227 txt = ""
1228 line, col = self.getCursorPosition()
1229 if self.hasSelectedText():
1230 lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
1231 if line == lineFrom:
1232 txt = self.text(line)[indexFrom:].rstrip()
1233 elif line == lineTo:
1234 txt = self.text(line)[:indexTo]
1235 else:
1236 txt = self.text(line)[col:].rstrip()
1237
1238 if txt:
1239 line, col = self.__getEndPos()
1240 self.setCursorPosition(line, col)
1241 self.insert(txt)
1213 1242
1214 def __QScintillaLeftCommand(self, method, allLinesAllowed=False): 1243 def __QScintillaLeftCommand(self, method, allLinesAllowed=False):
1215 """ 1244 """
1216 Private method to handle a QScintilla command working to the left. 1245 Private method to handle a QScintilla command working to the left.
1217 1246
1227 elif self.text(line).startswith(sys.ps2): 1256 elif self.text(line).startswith(sys.ps2):
1228 if col > len(sys.ps2): 1257 if col > len(sys.ps2):
1229 method() 1258 method()
1230 elif col > 0: 1259 elif col > 0:
1231 method() 1260 method()
1261 else:
1262 method()
1232 1263
1233 def __QScintillaCharLeft(self): 1264 def __QScintillaCharLeft(self):
1234 """ 1265 """
1235 Private method to handle the Cursor Left command. 1266 Private method to handle the Cursor Left command.
1236 """ 1267 """
1247 Private method to handle a QScintilla command working to the right. 1278 Private method to handle a QScintilla command working to the right.
1248 1279
1249 @param method shell method to execute 1280 @param method shell method to execute
1250 """ 1281 """
1251 if self.__isCursorOnLastLine(): 1282 if self.__isCursorOnLastLine():
1283 method()
1284 else:
1252 method() 1285 method()
1253 1286
1254 def __QScintillaCharRight(self): 1287 def __QScintillaCharRight(self):
1255 """ 1288 """
1256 Private method to handle the Cursor Right command. 1289 Private method to handle the Cursor Right command.
1302 if self.isListActive(): 1335 if self.isListActive():
1303 self.SendScintilla(cmd) 1336 self.SendScintilla(cmd)
1304 elif self.__isCursorOnLastLine(): 1337 elif self.__isCursorOnLastLine():
1305 self.moveCursorToEOL() 1338 self.moveCursorToEOL()
1306 1339
1307 def __QScintillaLineUp(self, cmd): 1340 def __QScintillaHistoryUp(self, cmd):
1308 """ 1341 """
1309 Private method to handle the Up key. 1342 Private method to handle the Ctrl+Up key.
1310 1343
1311 @param cmd QScintilla command 1344 @param cmd QScintilla command
1312 """ 1345 """
1313 if self.isListActive(): 1346 line, col = self.__getEndPos()
1314 self.SendScintilla(cmd) 1347 buf = self.text(line)
1315 else: 1348 if buf.startswith(sys.ps1):
1316 line, col = self.__getEndPos() 1349 buf = buf.replace(sys.ps1, "")
1317 buf = self.text(line) 1350 if buf.startswith(sys.ps2):
1318 if buf.startswith(sys.ps1): 1351 buf = buf.replace(sys.ps2, "")
1319 buf = buf.replace(sys.ps1, "") 1352 if buf and self.incrementalSearchActive:
1320 if buf.startswith(sys.ps2): 1353 if self.incrementalSearchString:
1321 buf = buf.replace(sys.ps2, "") 1354 idx = self.__rsearchHistory(self.incrementalSearchString,
1322 if buf and self.incrementalSearchActive: 1355 self.histidx)
1323 if self.incrementalSearchString: 1356 if idx >= 0:
1324 idx = self.__rsearchHistory(self.incrementalSearchString, 1357 self.histidx = idx
1325 self.histidx) 1358 self.__useHistory()
1326 if idx >= 0:
1327 self.histidx = idx
1328 self.__useHistory()
1329 else:
1330 idx = self.__rsearchHistory(buf)
1331 if idx >= 0:
1332 self.histidx = idx
1333 self.incrementalSearchString = buf
1334 self.__useHistory()
1335 else: 1359 else:
1336 if self.histidx < 0: 1360 idx = self.__rsearchHistory(buf)
1337 self.histidx = len(self.history) 1361 if idx >= 0:
1338 if self.histidx > 0: 1362 self.histidx = idx
1339 self.histidx = self.histidx - 1 1363 self.incrementalSearchString = buf
1340 self.__useHistory() 1364 self.__useHistory()
1341 1365 else:
1342 def __QScintillaLineDown(self, cmd): 1366 if self.histidx < 0:
1343 """ 1367 self.histidx = len(self.history)
1344 Private method to handle the Down key. 1368 if self.histidx > 0:
1369 self.histidx = self.histidx - 1
1370 self.__useHistory()
1371
1372 def __QScintillaHistoryDown(self, cmd):
1373 """
1374 Private method to handle the Ctrl+Down key.
1345 1375
1346 @param cmd QScintilla command 1376 @param cmd QScintilla command
1347 """ 1377 """
1348 if self.isListActive(): 1378 line, col = self.__getEndPos()
1349 self.SendScintilla(cmd) 1379 buf = self.text(line)
1350 else: 1380 if buf.startswith(sys.ps1):
1351 line, col = self.__getEndPos() 1381 buf = buf.replace(sys.ps1, "")
1352 buf = self.text(line) 1382 if buf.startswith(sys.ps2):
1353 if buf.startswith(sys.ps1): 1383 buf = buf.replace(sys.ps2, "")
1354 buf = buf.replace(sys.ps1, "") 1384 if buf and self.incrementalSearchActive:
1355 if buf.startswith(sys.ps2): 1385 if self.incrementalSearchString:
1356 buf = buf.replace(sys.ps2, "") 1386 idx = self.__searchHistory(
1357 if buf and self.incrementalSearchActive: 1387 self.incrementalSearchString, self.histidx)
1358 if self.incrementalSearchString: 1388 if idx >= 0:
1359 idx = self.__searchHistory( 1389 self.histidx = idx
1360 self.incrementalSearchString, self.histidx) 1390 self.__useHistory()
1361 if idx >= 0:
1362 self.histidx = idx
1363 self.__useHistory()
1364 else:
1365 idx = self.__searchHistory(buf)
1366 if idx >= 0:
1367 self.histidx = idx
1368 self.incrementalSearchString = buf
1369 self.__useHistory()
1370 else: 1391 else:
1371 if self.histidx >= 0 and self.histidx < len(self.history): 1392 idx = self.__searchHistory(buf)
1372 self.histidx += 1 1393 if idx >= 0:
1394 self.histidx = idx
1395 self.incrementalSearchString = buf
1373 self.__useHistory() 1396 self.__useHistory()
1397 else:
1398 if self.histidx >= 0 and self.histidx < len(self.history):
1399 self.histidx += 1
1400 self.__useHistory()
1374 1401
1375 def __QScintillaCharLeftExtend(self): 1402 def __QScintillaCharLeftExtend(self):
1376 """ 1403 """
1377 Private method to handle the Extend Selection Left command. 1404 Private method to handle the Extend Selection Left command.
1378 """ 1405 """

eric ide

mercurial