@@ -286,11 +286,11 @@ def check_selection(self):
286286 Check if selected text is r/w,
287287 otherwise remove read-only parts of selection
288288 """
289- if self .current_prompt_pos is None :
290- self .move_cursor_to_end ()
291- return
289+ # if self.current_prompt_pos is None:
290+ # self.move_cursor_to_end()
291+ # return
292292 line_from , index_from , line_to , index_to = self .getSelection ()
293- pline , pindex = self .current_prompt_pos
293+ pline , pindex = self .getCursorPosition ()
294294 if line_from < pline or \
295295 (line_from == pline and index_from < pindex ):
296296 self .setSelection (pline , pindex , line_to , index_to )
@@ -377,27 +377,38 @@ def keyPressEvent(self, e):
377377 elif e .key () == Qt .Key_Left :
378378 e .accept ()
379379 if e .modifiers () & Qt .ShiftModifier :
380- if e .modifiers () & Qt .ControlModifier :
381- self .SendScintilla (QsciScintilla .SCI_WORDLEFTEXTEND )
382- else :
383- self .SendScintilla (QsciScintilla .SCI_CHARLEFTEXTEND )
380+ if index > 4 :
381+ if e .modifiers () & Qt .ControlModifier :
382+ self .SendScintilla (QsciScintilla .SCI_WORDLEFTEXTEND )
383+ else :
384+ self .SendScintilla (QsciScintilla .SCI_CHARLEFTEXTEND )
384385 else :
385- if e .modifiers () & Qt .ControlModifier :
386- self .SendScintilla (QsciScintilla .SCI_WORDLEFT )
387- else :
388- self .SendScintilla (QsciScintilla .SCI_CHARLEFT )
386+ if index > 4 :
387+ if e .modifiers () & Qt .ControlModifier :
388+ self .SendScintilla (QsciScintilla .SCI_WORDLEFT )
389+ else :
390+ self .SendScintilla (QsciScintilla .SCI_CHARLEFT )
389391 elif e .key () == Qt .Key_Right :
390392 e .accept ()
391393 if e .modifiers () & Qt .ShiftModifier :
392- if e .modifiers () & Qt .ControlModifier :
393- self .SendScintilla (QsciScintilla .SCI_WORDRIGHTEXTEND )
394- else :
395- self .SendScintilla (QsciScintilla .SCI_CHARRIGHTEXTEND )
394+ if index >= 4 :
395+ if e .modifiers () & Qt .ControlModifier :
396+ self .SendScintilla (QsciScintilla .SCI_WORDRIGHTEXTEND )
397+ else :
398+ self .SendScintilla (QsciScintilla .SCI_CHARRIGHTEXTEND )
396399 else :
397- if e .modifiers () & Qt .ControlModifier :
398- self .SendScintilla (QsciScintilla .SCI_WORDRIGHT )
399- else :
400- self .SendScintilla (QsciScintilla .SCI_CHARRIGHT )
400+ if index >= 4 :
401+ if e .modifiers () & Qt .ControlModifier :
402+ self .SendScintilla (QsciScintilla .SCI_WORDRIGHT )
403+ else :
404+ self .SendScintilla (QsciScintilla .SCI_CHARRIGHT )
405+ elif e .key () == Qt .Key_Delete :
406+ if self .hasSelectedText ():
407+ self .check_selection ()
408+ self .removeSelectedText ()
409+ elif self .is_cursor_on_last_line ():
410+ self .SendScintilla (QsciScintilla .SCI_CLEAR )
411+ event .accept ()
401412 ## TODO: press event for auto-completion file directory
402413 #elif e.key() == Qt.Key_Tab:
403414 #self.show_file_completion()
0 commit comments