Beispiel #1
0
def multi_edit():
    ''' main entry point '''
    
    # multi_edit flags
    ACTION_PREPEND = 0
    ACTION_APPEND = 1
    ACTION_OVERWRITE = 2

    def select_words(current_position, action_type):
        ''' Creates a list of position tuples by using a
            regular expression with boundary flag /b,
            current cursor position gets removed from list
            In addition, creates multiple selection cursors.
            Has undo functionality
        '''

        matches = []
        editor.research('\\b{}\\b'.format(current_word),lambda m: matches.append(m.span(0)))
        matches.remove((word_start_position,word_end_position))
                        
        if action_type == ACTION_PREPEND:
            editor.setSelection(current_position,current_position)
            [editor.addSelection(x[0],x[0]) for x in matches]
        elif action_type == ACTION_APPEND:
            editor.setSelection(current_position,current_position)
            [editor.addSelection(x[1],x[1]) for x in matches]
        elif action_type == ACTION_OVERWRITE:
            editor.setSelection(word_start_position,word_end_position)
            [editor.addSelection(x[0],x[1]) for x in matches]
        else:
            return None
        editor.setMainSelection(0)


    editor.beginUndoAction()

    current_word = editor.getCurrentWord()
    if current_word != '':
        current_position = editor.getCurrentPos()
        word_start_position = editor.wordStartPosition(current_position, True)
        word_end_position = editor.wordEndPosition(current_position, True)
        
        if word_start_position == current_position:
            select_words(current_position, ACTION_PREPEND)
        elif word_end_position == current_position:
            select_words(current_position, ACTION_APPEND)
        else:
            select_words(current_position, ACTION_OVERWRITE)

    editor.endUndoAction()
Beispiel #2
0
def multi_edit():
    ''' main entry point '''

    # multi_edit flags
    ACTION_PREPEND = 0
    ACTION_APPEND = 1
    ACTION_OVERWRITE = 2

    def select_words(current_position, action_type):
        ''' Creates a list of position tuples by using a
            regular expression with boundary flag /b,
            current cursor position gets removed from list
            In addition, creates multiple selection cursors.
            Has undo functionality
        '''

        matches = []
        editor.research('\\b{}\\b'.format(current_word),
                        lambda m: matches.append(m.span(0)))
        matches.remove((word_start_position, word_end_position))

        if action_type == ACTION_PREPEND:
            editor.setSelection(current_position, current_position)
            [editor.addSelection(x[0], x[0]) for x in matches]
        elif action_type == ACTION_APPEND:
            editor.setSelection(current_position, current_position)
            [editor.addSelection(x[1], x[1]) for x in matches]
        elif action_type == ACTION_OVERWRITE:
            editor.setSelection(word_start_position, word_end_position)
            [editor.addSelection(x[0], x[1]) for x in matches]
        else:
            return None
        editor.setMainSelection(0)

    editor.beginUndoAction()

    current_word = editor.getCurrentWord()
    if current_word != '':
        current_position = editor.getCurrentPos()
        word_start_position = editor.wordStartPosition(current_position, True)
        word_end_position = editor.wordEndPosition(current_position, True)

        if word_start_position == current_position:
            select_words(current_position, ACTION_PREPEND)
        elif word_end_position == current_position:
            select_words(current_position, ACTION_APPEND)
        else:
            select_words(current_position, ACTION_OVERWRITE)

    editor.endUndoAction()
Beispiel #3
0
 def callback_scintillawrapper_int_position_bool(self, args):
     editor.clearCallbacks()
     editor.setText('abcdef ghijkl mnopqrst')
     wordStart = editor.wordStartPosition(10, False)
     self.assertEqual(wordStart, 7)
     self.callbackCalled = True
Beispiel #4
0
 def test_scintillawrapper_int_position_bool(self):
     editor.write('abcdef ghijkl mnopqrst')
     wordStart = editor.wordStartPosition(10, False)
     self.assertEqual(wordStart, 7)