wiki:NextAndPreviousHeading

Creates two shortcuts Alt+Up and Alt+Down to move cursor to previous or next heading respectively. UPDATE:v2 with regex code.

# -*- coding: utf-8 -*-
WIKIDPAD_PLUGIN = (("MenuFunctions",1),)

def describeMenuItems(pwiki):

        return ((NextHeading, "Next Heading\tAlt+Down", "Prev Heading"),
		(PrevHeading, "Prev Heading\tAlt+Up", "Next Heading"),
)


import string
import wx

def PrevHeading(pwiki, evt):
	import re
	editor = pwiki.getActiveEditor()
	full_text = editor.GetText()
	matches = [i.start() for i in re.finditer(re.compile("^\+",re.MULTILINE), full_text)]
	curpos=editor.GetCurrentPos()
	if len(matches)>0:
	    if editor.GetCurrentLine()>0:
			last=0
			for i in matches:
				if curpos>i:
					last=i
				else:
					break

				
			
	    else:
	    	last=matches.pop()

	    editor.GotoPos(last) 

def NextHeading(pwiki, evt):
	import re
	editor = pwiki.getActiveEditor()
	full_text = editor.GetText()
	matches = [i.start() for i in re.finditer(re.compile("^\+",re.MULTILINE), full_text)]
	curpos=editor.GetCurrentPos()
	if len(matches)>0:
		last=0
		for i in matches:
			if curpos<i:
				last=i
				break

		editor.GotoPos(last) 
				
		
		
		
Last modified 7 years ago Last modified on Jan 20, 2011 5:14:18 PM