Browse Source

CDB: Rework pageUp / pageDown behaviour

lviguier 6 tháng trước cách đây
mục cha
commit
f255be1c0c
2 tập tin đã thay đổi với 52 bổ sung2 xóa
  1. 7 0
      hide/comp/cdb/Cursor.hx
  2. 45 2
      hide/comp/cdb/Editor.hx

+ 7 - 0
hide/comp/cdb/Cursor.hx

@@ -169,6 +169,13 @@ class Cursor {
 			addElementToSelection(line.table, line, x, y);
 
 
+		var c = getCell();
+		var l = getLine();
+		if (c != null)
+			untyped c.elementHtml.scrollIntoViewIfNeeded();
+		else if (l != null)
+			untyped l.element.get(0).scrollIntoViewIfNeeded();
+
 		update();
 	}
 

+ 45 - 2
hide/comp/cdb/Editor.hx

@@ -204,10 +204,53 @@ class Editor extends Component {
 			cursor.move( e.shiftKey ? -1 : 1, 0, false, false, true);
 			return true;
 		case K.PGUP:
-			cursor.move(0, -10, e.shiftKey, e.ctrlKey, e.altKey);
+			var scrollView = element.parent(".hide-scroll");
+			var stickyElHeight = scrollView.find(".separator").height();
+			if (Math.isNaN(stickyElHeight))
+				stickyElHeight = scrollView.find("thead").outerHeight();
+			else
+				stickyElHeight += scrollView.find("thead").outerHeight();
+
+			var lines = scrollView.find("tbody").find(".start");
+			var idx = lines.length - 1;
+			while (idx >= 0) {
+				var b = lines[idx].getBoundingClientRect();
+				if (b.top <= stickyElHeight)
+					break;
+				idx--;
+			}
+
+			cursor.set(cursor.table, cursor.x, idx);
+			lines.get(idx).scrollIntoView({ block: js.html.ScrollLogicalPosition.END });
+
+			// Handle sticky elements
+			scrollView.scrollTop(scrollView.scrollTop() + scrollView.parent().siblings(".tabs-header").outerHeight());
+
 			return true;
+
 		case K.PGDOWN:
-			cursor.move(0, 10, e.shiftKey, e.ctrlKey, e.altKey);
+			var scrollView = element.parent(".hide-scroll");
+			var height = scrollView.outerHeight() - (scrollView.find("thead").outerHeight() + scrollView.parent().siblings(".tabs-header").outerHeight());
+			var lines = scrollView.find("tbody").find(".start");
+			var idx = 0;
+			for (el in lines) {
+				var b = el.getBoundingClientRect();
+				if (b.top >= height)
+					break;
+				idx++;
+			}
+
+			if (idx > lines.length - 1)
+				idx = lines.length - 1;
+			lines.get(idx).scrollIntoView(true);
+			cursor.set(cursor.table, cursor.x, idx);
+
+			// Handle sticky elements
+			var sepHeight = scrollView.find(".separator").height();
+			if (Math.isNaN(sepHeight))
+				sepHeight = 0;
+			scrollView.scrollTop(scrollView.scrollTop() - (scrollView.find("thead").height() + sepHeight));
+
 			return true;
 		case K.SPACE:
 			e.preventDefault(); // prevent scroll