Skip to content

Commit

Permalink
Merge pull request davidbalbert#128 from davidbalbert/remove-responsi…
Browse files Browse the repository at this point in the history
…ve-scrolling

Rework scrolling and layout
  • Loading branch information
davidbalbert authored Mar 31, 2024
2 parents 628b339 + b462b81 commit f2836c3
Show file tree
Hide file tree
Showing 28 changed files with 1,144 additions and 309 deletions.
65 changes: 53 additions & 12 deletions Watt.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
6315D3002A9B769100B8A077 /* AttributedRope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6315D2FF2A9B769100B8A077 /* AttributedRope.swift */; };
6315D3022A9BD00F00B8A077 /* AttributedRopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6315D3012A9BD00F00B8A077 /* AttributedRopeTests.swift */; };
631FD2652A696D27005FA854 /* Heights.swift in Sources */ = {isa = PBXBuildFile; fileRef = 631FD2642A696D27005FA854 /* Heights.swift */; };
63206D2A2BA74AF600CAFBC4 /* TextView+Scrolling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63206D292BA74AF600CAFBC4 /* TextView+Scrolling.swift */; };
63206D2D2BA8E8F400CAFBC4 /* Autoscroller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63206D2C2BA8E8F400CAFBC4 /* Autoscroller.swift */; };
63206D362BAB635500CAFBC4 /* Motion in Frameworks */ = {isa = PBXBuildFile; productRef = 63206D352BAB635500CAFBC4 /* Motion */; };
63206D382BAB707E00CAFBC4 /* ScrollManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63206D372BAB707E00CAFBC4 /* ScrollManager.swift */; };
63206D3A2BB5C65500CAFBC4 /* CGVector+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63206D392BB5C65500CAFBC4 /* CGVector+Extensions.swift */; };
63267C292B97BF0B00F6E968 /* BTreeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63267C282B97BF0B00F6E968 /* BTreeTests.swift */; };
63286AE22A13DF5D00839B25 /* ClipView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63286AE12A13DF5D00839B25 /* ClipView.swift */; };
632A73722B87C69F009F38C3 /* Range+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 632A73712B87C69F009F38C3 /* Range+Extensions.swift */; };
Expand Down Expand Up @@ -130,6 +135,10 @@
6315D2FF2A9B769100B8A077 /* AttributedRope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributedRope.swift; sourceTree = "<group>"; };
6315D3012A9BD00F00B8A077 /* AttributedRopeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AttributedRopeTests.swift; path = WattTests/AttributedRopeTests.swift; sourceTree = SOURCE_ROOT; };
631FD2642A696D27005FA854 /* Heights.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Heights.swift; sourceTree = "<group>"; };
63206D292BA74AF600CAFBC4 /* TextView+Scrolling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TextView+Scrolling.swift"; sourceTree = "<group>"; };
63206D2C2BA8E8F400CAFBC4 /* Autoscroller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Autoscroller.swift; sourceTree = "<group>"; };
63206D372BAB707E00CAFBC4 /* ScrollManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollManager.swift; sourceTree = "<group>"; };
63206D392BB5C65500CAFBC4 /* CGVector+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGVector+Extensions.swift"; sourceTree = "<group>"; };
63267C282B97BF0B00F6E968 /* BTreeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTreeTests.swift; sourceTree = "<group>"; };
63286AE12A13DF5D00839B25 /* ClipView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClipView.swift; sourceTree = "<group>"; };
632A73712B87C69F009F38C3 /* Range+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Range+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -247,6 +256,7 @@
63F30E672AA90012009929F7 /* TreeSitter in Frameworks */,
63DD20E72B76BBE500E55747 /* OrderedCollections in Frameworks */,
63359A3E2AA9115100082762 /* TreeSitterC in Frameworks */,
63206D362BAB635500CAFBC4 /* Motion in Frameworks */,
63E32EB22AF3F51600EDB062 /* StandardKeyBindingResponder in Frameworks */,
635F815B2AA9198200553E23 /* TreeSitterObjC in Frameworks */,
);
Expand All @@ -270,6 +280,23 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
63206D2B2BA8E73000CAFBC4 /* Utilities */ = {
isa = PBXGroup;
children = (
63C2C0452B4DF34D00BFB976 /* SimpleProxy.h */,
63C2C0462B4DF34D00BFB976 /* SimpleProxy.m */,
63206D2C2BA8E8F400CAFBC4 /* Autoscroller.swift */,
63DD20DA2B7278E400E55747 /* CheckedContinuationReference.swift */,
637E58532B8415A400C498EE /* DragAndDrop.swift */,
63A95D832B5462D60032E8B9 /* FSEvents.swift */,
63C2C03E2B4D95EB00BFB976 /* OutlineViewDiffableDataSource.swift */,
63206D372BAB707E00CAFBC4 /* ScrollManager.swift */,
63B8B1752A9F890100F32C2C /* Utilities.swift */,
63A618712A0EAF2000E70B0E /* Weak.swift */,
);
path = Utilities;
sourceTree = "<group>";
};
63359A392AA9081B00082762 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -310,6 +337,7 @@
637BC1432A156B820089A34D /* CGPoint+Extensions.swift */,
637BC1412A156B620089A34D /* CGRect+Extensions.swift */,
637BC1452A156B9B0089A34D /* CGSize+Extensions.swift */,
63206D392BB5C65500CAFBC4 /* CGVector+Extensions.swift */,
63820B8C2A7164A500CC7458 /* Collection+Extensions.swift */,
6396DD252B433775000F85D1 /* Comparable+Extensions.swift */,
63DD20E12B76B59300E55747 /* Logger+Extensions.swift */,
Expand All @@ -328,6 +356,7 @@
636E850F2B6AAD7C00772ECE /* TextView */ = {
isa = PBXGroup;
children = (
63286AE12A13DF5D00839B25 /* ClipView.swift */,
635B36AE2AAE5424002FAE70 /* Highlighter.swift */,
637867802A1BEA960039960E /* InsertionPointLayer.swift */,
635B36AC2AAE4D7F002FAE70 /* Language.swift */,
Expand All @@ -341,6 +370,7 @@
63A618752A0FD61B00E70B0E /* TextView+LineNumbers.swift */,
637867722A1BD1E10039960E /* TextView+Mouse.swift */,
6396DD2D2B45A5DE000F85D1 /* TextView+Pasteboard.swift */,
63206D292BA74AF600CAFBC4 /* TextView+Scrolling.swift */,
637867702A17F7460039960E /* TextView+Selection.swift */,
635B36B02AAFCD95002FAE70 /* Theme.swift */,
635F815C2AA9E51900553E23 /* TreeSitter.swift */,
Expand Down Expand Up @@ -409,21 +439,10 @@
children = (
6356588F2ACD9D5400F1DC63 /* Themes */,
6372889829FD8E1A005B95E5 /* Watt.entitlements */,
63C2C0452B4DF34D00BFB976 /* SimpleProxy.h */,
63C2C04A2B4DF86100BFB976 /* Watt-Bridging-Header.h */,
63C2C0462B4DF34D00BFB976 /* SimpleProxy.m */,
6372889729FD8E1A005B95E5 /* Info.plist */,
6372888B29FD8E19005B95E5 /* AppDelegate.swift */,
63DD20DA2B7278E400E55747 /* CheckedContinuationReference.swift */,
63286AE12A13DF5D00839B25 /* ClipView.swift */,
6364DDA02B6C403400886DE3 /* ContainerViewController.swift */,
637E58532B8415A400C498EE /* DragAndDrop.swift */,
63A95D832B5462D60032E8B9 /* FSEvents.swift */,
63C2C03E2B4D95EB00BFB976 /* OutlineViewDiffableDataSource.swift */,
63A95D872B55B9D70032E8B9 /* UserDefaults+Keys.swift */,
63B8B1752A9F890100F32C2C /* Utilities.swift */,
63B8B1772A9F8A3A00F32C2C /* UtilitiesTest.swift */,
63A618712A0EAF2000E70B0E /* Weak.swift */,
63A618612A0C3AE200E70B0E /* Moby Dick.txt */,
6372889229FD8E1A005B95E5 /* Assets.xcassets */,
636E84662B683F3A00772ECE /* Localizable.xcstrings */,
Expand All @@ -434,6 +453,7 @@
6372889429FD8E1A005B95E5 /* MainMenu.xib */,
636E85102B6AADC900772ECE /* Rope */,
636E850F2B6AAD7C00772ECE /* TextView */,
63206D2B2BA8E73000CAFBC4 /* Utilities */,
63C2C04E2B4F3B8E00BFB976 /* Workspace */,
);
path = Watt;
Expand All @@ -449,6 +469,7 @@
63D5463F2AFC304B00C72CDE /* LayoutManagerTests.swift */,
63F0468E2A65D417001B8DA8 /* RopeTests.swift */,
6315D2FD2A96630F00B8A077 /* SpansTests.swift */,
63B8B1772A9F8A3A00F32C2C /* UtilitiesTest.swift */,
634A70A32B1F7A0A00BDD0D3 /* Support */,
);
path = WattTests;
Expand All @@ -475,17 +496,18 @@
63C2C04E2B4F3B8E00BFB976 /* Workspace */ = {
isa = PBXGroup;
children = (
6364DDA02B6C403400886DE3 /* ContainerViewController.swift */,
63C2C04F2B4F3BB700BFB976 /* Dirent.swift */,
63D280882B5B275900CDCF04 /* DirentTextField.swift */,
6364DDA22B6C408700886DE3 /* DocumentPaneViewController.swift */,
63DD20D82B71A53200E55747 /* Window.swift */,
6364DD9E2B6C3BB000886DE3 /* WindowController.swift */,
63C541EA2B486210001C370B /* Workspace.swift */,
636DD5302B599E150064C989 /* Workspace+LoadRequest.swift */,
63C2C03C2B4D95CE00BFB976 /* WorkspaceBrowserViewController.swift */,
63D280AA2B605A2A00CDCF04 /* WorkspacePasteboardWriter.swift */,
63DC933C2B473BB5001018FE /* WorkspaceViewController.swift */,
6364DD962B6C05C300886DE3 /* WorkspaceWindowController.swift */,
63DD20D82B71A53200E55747 /* Window.swift */,
);
path = Workspace;
sourceTree = "<group>";
Expand Down Expand Up @@ -513,6 +535,7 @@
63E32EB12AF3F51600EDB062 /* StandardKeyBindingResponder */,
63C2C0412B4D97E700BFB976 /* Tree */,
63DD20E62B76BBE500E55747 /* OrderedCollections */,
63206D352BAB635500CAFBC4 /* Motion */,
);
productName = Watt;
productReference = 6372888829FD8E19005B95E5 /* Watt.app */;
Expand Down Expand Up @@ -596,6 +619,7 @@
634A70A02B1F79CB00BDD0D3 /* XCRemoteSwiftPackageReference "CwlPreconditionTesting" */,
63C2C0402B4D97E700BFB976 /* XCRemoteSwiftPackageReference "Tree" */,
63DD20E52B76BBE500E55747 /* XCRemoteSwiftPackageReference "swift-collections" */,
63206D342BAB635500CAFBC4 /* XCRemoteSwiftPackageReference "Motion" */,
);
productRefGroup = 6372888929FD8E19005B95E5 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -646,6 +670,7 @@
6315D3002A9B769100B8A077 /* AttributedRope.swift in Sources */,
63D280892B5B275900CDCF04 /* DirentTextField.swift in Sources */,
63286AE22A13DF5D00839B25 /* ClipView.swift in Sources */,
63206D2A2BA74AF600CAFBC4 /* TextView+Scrolling.swift in Sources */,
63A95D842B5462D60032E8B9 /* FSEvents.swift in Sources */,
63DD20D92B71A53200E55747 /* Window.swift in Sources */,
637BC1422A156B620089A34D /* CGRect+Extensions.swift in Sources */,
Expand All @@ -654,6 +679,7 @@
6364DDA82B6C49C700886DE3 /* DocumentViewController.swift in Sources */,
6346D1952A06EC2900CFB7EE /* TextContainer.swift in Sources */,
6396DD262B433781000F85D1 /* Comparable+Extensions.swift in Sources */,
63206D2D2BA8E8F400CAFBC4 /* Autoscroller.swift in Sources */,
63B8B1762A9F890100F32C2C /* Utilities.swift in Sources */,
63F25BE12A689D2400DEACCF /* Line.swift in Sources */,
637867872A1FB2C50039960E /* NSRange+Extensions.swift in Sources */,
Expand Down Expand Up @@ -686,6 +712,7 @@
6378677D2A1BE3FE0039960E /* LineNumberLayer.swift in Sources */,
632A73722B87C69F009F38C3 /* Range+Extensions.swift in Sources */,
63F0468A2A65D3EA001B8DA8 /* BTree.swift in Sources */,
63206D382BAB707E00CAFBC4 /* ScrollManager.swift in Sources */,
63DD20DB2B7278E400E55747 /* CheckedContinuationReference.swift in Sources */,
637867812A1BEA960039960E /* InsertionPointLayer.swift in Sources */,
63F25BE52A68A27600DEACCF /* LineFragment.swift in Sources */,
Expand All @@ -699,6 +726,7 @@
63F25BD92A683CC500DEACCF /* Buffer.swift in Sources */,
63DD20DF2B73CFF200E55747 /* NSObject+Extensions.m in Sources */,
63DD20E22B76B59300E55747 /* Logger+Extensions.swift in Sources */,
63206D3A2BB5C65500CAFBC4 /* CGVector+Extensions.swift in Sources */,
637867712A17F7460039960E /* TextView+Selection.swift in Sources */,
6364DD972B6C05C300886DE3 /* WorkspaceWindowController.swift in Sources */,
63D280902B5EC14D00CDCF04 /* NSFilePromiseReceiver+Extensions.swift in Sources */,
Expand Down Expand Up @@ -1074,6 +1102,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
63206D342BAB635500CAFBC4 /* XCRemoteSwiftPackageReference "Motion" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/b3ll/Motion";
requirement = {
branch = main;
kind = branch;
};
};
63359A3C2AA9115100082762 /* XCRemoteSwiftPackageReference "tree-sitter-c" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/tree-sitter/tree-sitter-c";
Expand Down Expand Up @@ -1117,6 +1153,11 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
63206D352BAB635500CAFBC4 /* Motion */ = {
isa = XCSwiftPackageProductDependency;
package = 63206D342BAB635500CAFBC4 /* XCRemoteSwiftPackageReference "Motion" */;
productName = Motion;
};
63359A3D2AA9115100082762 /* TreeSitterC */ = {
isa = XCSwiftPackageProductDependency;
package = 63359A3C2AA9115100082762 /* XCRemoteSwiftPackageReference "tree-sitter-c" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"version" : "2.2.0"
}
},
{
"identity" : "motion",
"kind" : "remoteSourceControl",
"location" : "https://github.com/b3ll/Motion",
"state" : {
"branch" : "main",
"revision" : "533e148d5f239cbdc5ad6b91b7c32b94bc005981"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
Expand All @@ -27,6 +36,15 @@
"version" : "1.1.0"
}
},
{
"identity" : "swift-numerics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-numerics",
"state" : {
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
"version" : "1.0.2"
}
},
{
"identity" : "tree",
"kind" : "remoteSourceControl",
Expand Down
4 changes: 2 additions & 2 deletions Watt/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22689"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand Down
25 changes: 0 additions & 25 deletions Watt/ClipView.swift

This file was deleted.

10 changes: 10 additions & 0 deletions Watt/Extensions/CGPoint+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ extension CGPoint: Hashable {
}
}

extension CGPoint {
static func + (lhs: CGPoint, rhs: CGVector) -> CGPoint {
CGPoint(x: lhs.x + rhs.dx, y: lhs.y + rhs.dy)
}
}

extension CGPoint {
func clamped(to rect: CGRect) -> CGPoint {
CGPoint(x: x.clamped(to: rect.minX...rect.maxX), y: y.clamped(to: rect.minY...rect.maxY))
}

func rounded() -> CGPoint {
CGPoint(x: x.rounded(), y: y.rounded())
}
}
18 changes: 18 additions & 0 deletions Watt/Extensions/CGVector+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// CGVector+Extensions.swift
// Watt
//
// Created by David Albert on 3/28/24.
//

import CoreGraphics

extension CGVector: AdditiveArithmetic {
public static func + (lhs: CGVector, rhs: CGVector) -> CGVector {
.init(dx: lhs.dx + rhs.dx, dy: lhs.dy + rhs.dy)
}

public static func - (lhs: CGVector, rhs: CGVector) -> CGVector {
.init(dx: lhs.dx - rhs.dx, dy: lhs.dy - rhs.dy)
}
}
7 changes: 7 additions & 0 deletions Watt/LayoutManager/Heights.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ extension Heights {
func yOffset(upThroughPosition offset: Int) -> CGFloat {
precondition(offset >= 0 && offset <= root.count, "Position out of bounds")

// I forget exactly why we special case offset == root.count, but I think it's probably
// to deal with empty last lines.
if offset == root.count {
let i = endIndex
let (leaf, _) = i.read()!
Expand All @@ -426,6 +428,11 @@ extension Heights {
return root.count(.heights, upThrough: offset, edge: .leading)
}

func height(upThroughPosition offset: Int) -> CGFloat {
precondition(offset >= 0 && offset <= root.count, "Position out of bounds")
return root.count(.heights, upThrough: offset, edge: .trailing)
}

func position(upThroughYOffset yOffset: CGFloat) -> Int {
if yOffset < 0 {
return 0
Expand Down
Loading

0 comments on commit f2836c3

Please sign in to comment.