changeset 2554:2581df6b3483

auto-scroll edit textarea for ReST items
author RogerHaase <haaserd@gmail.com>
date Mon, 20 Jan 2014 14:48:00 -0700
parents 67ae770a22d5
children f56612ff00b3
files MoinMoin/converter/rst_in.py
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/converter/rst_in.py	Sat Jan 18 14:53:12 2014 -0700
+++ b/MoinMoin/converter/rst_in.py	Mon Jan 20 14:48:00 2014 -0700
@@ -23,6 +23,7 @@
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
+from flask import request
 from flask import g as flaskg
 
 from MoinMoin import config
@@ -53,6 +54,8 @@
         self.header_size = 1
         self.status = ['document']
         self.footnotes = dict()
+        self.last_lineno = 0
+        self.current_lineno = 0
 
     def dispatch_visit(self, node):
         """
@@ -62,6 +65,7 @@
         """
         node_name = node.__class__.__name__
         method = getattr(self, 'visit_' + node_name, self.unknown_visit)
+        self.current_lineno = node.line
         return method(node)
 
     def dispatch_departure(self, node):
@@ -91,6 +95,11 @@
         pass
 
     def open_moin_page_node(self, mointree_element):
+        if request.user_agent and flaskg.user.edit_on_doubleclick:
+            # add data-lineno attribute for auto-scrolling edit textarea (user_agent is None when running tests)
+            if self.last_lineno < self.current_lineno:
+                mointree_element.attrib[html.data_lineno] = self.current_lineno
+                self.last_lineno = self.current_lineno
         self.current_node.append(mointree_element)
         self.current_node = mointree_element
         self.path.append(mointree_element)