afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
afuna ([personal profile] afuna) wrote in [site community profile] changelog2009-07-06 04:17 pm

[dw-free] Keep S2 layer editor window cursor in same place when compiling

[commit: http://hg.dwscoalition.org/dw-free/rev/090bb06795f7]

http://bugs.dwscoalition.org/show_bug.cgi?id=401

Codemerge: remember position. (Also, take two on this commit.)

Patch from LiveJournal, prepared for Dreamwidth by [staff profile] denise.

Files modified:
  • htdocs/customize/advanced/layeredit.bml
  • htdocs/js/s2edit/s2edit.js
  • htdocs/js/s2edit/s2gui.js
  • htdocs/js/s2edit/xlib.js
--------------------------------------------------------------------------------
diff -r 8dc427394a17 -r 090bb06795f7 htdocs/customize/advanced/layeredit.bml
--- a/htdocs/customize/advanced/layeredit.bml	Mon Jul 06 16:11:28 2009 +0000
+++ b/htdocs/customize/advanced/layeredit.bml	Mon Jul 06 16:17:30 2009 +0000
@@ -146,18 +146,14 @@
 // -->
 </script>
 
+$includes
+
 <!--[if IE]>
 <style type="text/css">
     html {
         overflow: hidden;
     }
-</style>
-<![endif]-->
 
-$includes
-
-<!--[if IE]>
-<style type="text/css">
     div.reference {
         height: expression(xGetElementById('statusbar').offsetTop - (42 + 9 + 10) + "px");
     }
@@ -199,9 +195,9 @@
 
 </head>
 <body onMouseMove="s2processDrag(event)" onMouseUp="s2endDrag(event)">
-        <form method="post">
-        $formauth
-        <input type="hidden" name="action" value="compile" />
+    <form method="post" name="s2" action="" onsubmit="return s2submit()">
+    $formauth
+    <input type="hidden" name="action" value="compile" />
 
     <div class="header">
         <h1>$title</h1>
@@ -278,14 +274,9 @@
         <div class="gutter"> </div>
         <div id="status">Ready.</div>
     </div>
+    
+    </form>
 
-<script type="text/javascript">
-    if (navigator.userAgent.indexOf('Safari') > -1) {
-        xGetElementById('main').style.width = '100%';
-    }
-
-        s2init();
-</script>
 
 </body>
 </html>
diff -r 8dc427394a17 -r 090bb06795f7 htdocs/js/s2edit/s2edit.js
--- a/htdocs/js/s2edit/s2edit.js	Mon Jul 06 16:11:28 2009 +0000
+++ b/htdocs/js/s2edit/s2edit.js	Mon Jul 06 16:17:30 2009 +0000
@@ -28,3 +28,7 @@ function s2initIndex()
 {
 	s2index = new Object();
 }
+
+LiveJournal.register_hook('page_load', function () {
+  s2init();
+});
diff -r 8dc427394a17 -r 090bb06795f7 htdocs/js/s2edit/s2gui.js
--- a/htdocs/js/s2edit/s2gui.js	Mon Jul 06 16:11:28 2009 +0000
+++ b/htdocs/js/s2edit/s2gui.js	Mon Jul 06 16:17:30 2009 +0000
@@ -261,6 +261,16 @@ function s2buildReference()
 	s2buildClasses();
 	s2buildFunctions();
 	s2buildProperties();
+	
+	if (window.name)
+	{
+		setTimeout(function() {
+			var pos = window.name.split(':'), textarea = s2getCodeArea();
+			textarea.scrollTop = +pos[0] || 0;
+			nxpositionCursor(textarea, pos[1] || 0)
+			window.name = '';
+		}, 1)
+	}
 }
 
 // ---------------------------------------------------------------------------
@@ -449,3 +459,10 @@ function s2initDrag()
 		
 	return true;
 }
+
+function s2submit()
+{
+	// save position textarea, where reload page
+	var textarea = s2getCodeArea();
+	window.name = textarea.scrollTop + ':' + nxgetPositionCursor(textarea);
+}
diff -r 8dc427394a17 -r 090bb06795f7 htdocs/js/s2edit/xlib.js
--- a/htdocs/js/s2edit/xlib.js	Mon Jul 06 16:11:28 2009 +0000
+++ b/htdocs/js/s2edit/xlib.js	Mon Jul 06 16:17:30 2009 +0000
@@ -85,12 +85,28 @@ function nxpositionCursor(obj, pos)
 {
 	if (nxIE) {
 		var range = obj.createTextRange();
-		range.move('character', from);
+		range.collapse(true);
+		range.moveEnd('character', pos);
+		range.moveStart('character', pos);
 		range.select();		// TODO: test this
 	} else {
 		obj.selectionStart = obj.selectionEnd = pos;
 		obj.focus();
 	}
+}
+
+function nxgetPositionCursor(obj)
+{
+	if ('selectionStart' in obj) {
+		return obj.selectionStart;
+	}
+	if (document.selection && document.selection.createRange) {
+		obj.focus();
+		var range = document.selection.createRange();
+		return 0 - range.duplicate().moveStart('character', -100000);
+	}
+
+	return 0;
 }
 
 // Scrolls the object to the given line out of the given total number of lines.
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org