def test_scintillawrapper_void_int_int(self): editor.write('One\r\nTwo\r\nThree\r\nFour') editor.markerAddSet(2, 0x11) # marker 4 (0x10) and 0 (0x01) on line 2 markersBeforeMove = editor.markerGet(2) editor.insertText(0, 'Inserted\r\n') markersAfterMove = editor.markerGet(2) markersAfterMoveLine3 = editor.markerGet(3) self.assertEqual(markersBeforeMove, 0x11) self.assertEqual(markersAfterMove, 0) self.assertEqual(markersAfterMoveLine3, 0x11)
def find_correspondig_marker(next_marker_line, searching_marker_mask): start_marker_count = 0 end_marker_count = 0 # to avoid having two functions, markerNext or markerPrevious # gets assigned to find_marker variable if searching_marker_mask == MARK_HIDELINESEND_MASK: find_marker = editor.markerNext add_to_line_value = 1 start_marker_count = 1 else: find_marker = editor.markerPrevious add_to_line_value = -1 end_marker_count = 1 # the idea is to search as long for start and end markers # until we get the same amount for both while (start_marker_count != end_marker_count): next_marker_line = find_marker(next_marker_line + add_to_line_value, MARK_COMBINED_MASK) if (next_marker_line != -1): if (editor.markerGet(next_marker_line) & MARK_COMBINED_MASK) == MARK_COMBINED_MASK: if searching_marker_mask == MARK_HIDELINESEND_MASK: end_marker_count += 1 if end_marker_count == start_marker_count: break # found the matching marker start_marker_count += 1 else: start_marker_count += 1 if end_marker_count == start_marker_count: break # found the matching marker end_marker_count += 1 elif editor.markerGet(next_marker_line) & MARK_HIDELINESBEGIN_MASK: start_marker_count += 1 elif editor.markerGet(next_marker_line) & MARK_HIDELINESEND_MASK: end_marker_count += 1 else: msg = 'Now we are in trouble - should not happen !! ??' notepad.messageBox(msg, 'ERROR') list_all_markers() # only used for debugging purpose next_marker_line = -1 break return next_marker_line
def test_scintillawrapper_int_int_void(self): editor.write('One\r\nTwo\r\nThree\r\nFour') handle = editor.markerAdd(3, 4) # Add marker 4 at line 3 beforeMoveMarker = editor.markerGet(3) editor.insertText(0, 'Add a line\r\n') afterMove3 = editor.markerGet(3) afterMove4 = editor.markerGet(4) lineNumber = editor.markerLineFromHandle(handle) self.assertEqual(beforeMoveMarker & 0x10, 0x10) # marker 4 is 0x10, and there could be other markers on the line self.assertEqual(afterMove3 & 0x10, 0) # after the insert, line 3 should not contain the marker self.assertEqual(afterMove4 & 0x10, 0x10) # it should be on line 4 self.assertEqual(lineNumber, 4) # The lineNumber obtained from the handle, should also be 4
def toggle_bookmark(current_line): current_marker_mask = editor.markerGet(current_line) if (current_marker_mask & NPP_MARK_BOOKMARK_MASK) == NPP_MARK_BOOKMARK_MASK: editor.markerDelete(current_line, NPP_MARK_BOOKMARK) else: editor.markerAdd(current_line, NPP_MARK_BOOKMARK)
def sync_callback_MARGINCLICK(args): if args['margin'] == 1: # symbol margin clicked_line = editor.lineFromPosition(args['position']) current_marker_mask = editor.markerGet(clicked_line) # if clicked on a opening marker - find corresponding end marker if (current_marker_mask & MARK_HIDELINESBEGIN_MASK) == MARK_HIDELINESBEGIN_MASK: end_line = find_correspondig_marker(clicked_line, MARK_HIDELINESEND_MASK) show_lines(clicked_line, end_line) # else if clicked on a closing marker, then find corresponding start marker elif (current_marker_mask & MARK_HIDELINESEND_MASK) == MARK_HIDELINESEND_MASK: start_line = find_correspondig_marker(clicked_line, MARK_HIDELINESBEGIN_MASK) show_lines(start_line, clicked_line) else: # no hiding marker, just bookmark toggle_bookmark(clicked_line) # cheating npp ;-) toggle_bookmark(clicked_line) # double cheating npp :D
def main(): if editor.getSelectionEmpty(): # user hasn't selected anything, hide cursor line start_line = end_line = editor.lineFromPosition(editor.getCurrentPos()) else: start_line, end_line = editor.getUserLineSelection() total_number_less_one_line = editor.getLineCount() - 1 # zero-based # recalculate which lines to hide as first and last line cannot be hide start_line = start_line if start_line > 0 else 1 end_line = end_line if total_number_less_one_line > end_line else end_line - 1 # calculate at which lines marker need to be placed marker_start_line = start_line - 1 if start_line > 0 else start_line marker_end_line = end_line + 1 if end_line < total_number_less_one_line else end_line # recalculate in case that marker(start/end)lines are not visible # either because they are part of a folding tree or already hidden while not editor.getLineVisible(marker_start_line): marker_start_line -= 1 if not editor.getLineVisible(marker_end_line): visible_line = editor.visibleFromDocLine(marker_end_line) marker_end_line = editor.docLineFromVisible(visible_line) # check if there is already a marker set at those lines marker_at_marker_start_line = editor.markerGet(marker_start_line) marker_at_marker_end_line = editor.markerGet(marker_end_line) marker_already_set = False if (marker_at_marker_start_line & MARK_HIDELINESBEGIN_MASK) == MARK_HIDELINESBEGIN_MASK: marker_type = 'start' marker_already_set = True elif (marker_at_marker_end_line & MARK_HIDELINESEND_MASK) == MARK_HIDELINESEND_MASK: marker_type = 'end' marker_already_set = True # already markers set - inform user if marker_already_set: if EXTEND_AUTOMATICALLY is False: answer = notepad.messageBox(( 'There can only be one {} marker per line\r\n' 'Should it be extended instead?\r\n' "If it shouldn't, it doesn't do anything").format(marker_type), 'Info!', 4) if EXTEND_AUTOMATICALLY or answer == MESSAGEBOXFLAGS.RESULTYES: if marker_type == 'start': _matching_marker_line = find_correspondig_marker( marker_start_line, MARK_HIDELINESEND_MASK) _start_marker_line_to_delete = marker_start_line _end_marker_line_to_delete = _matching_marker_line else: _matching_marker_line = find_correspondig_marker( marker_end_line, MARK_HIDELINESBEGIN_MASK) _start_marker_line_to_delete = _matching_marker_line _end_marker_line_to_delete = marker_end_line editor.markerDelete(_start_marker_line_to_delete, MARK_HIDELINESBEGIN) editor.markerDelete(_start_marker_line_to_delete, MARK_HIDELINESUNDERLINE) editor.markerDelete(_end_marker_line_to_delete, MARK_HIDELINESEND) else: return editor.hideLines(start_line, end_line) editor.markerAdd(marker_start_line, MARK_HIDELINESBEGIN) editor.markerAdd(marker_start_line, MARK_HIDELINESUNDERLINE) editor.markerAdd(marker_end_line, MARK_HIDELINESEND) editor.gotoLine(marker_start_line)
def list_all_markers(): # used only for debugging purpose for i in range(editor.getLineCount()): _marker = editor.markerGet(i) if _marker > 0: console.writeError('{:>3} = {}\n'.format(i, _marker))