Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit52205b2

Browse files
authored
Fixed scrolling when using format on save (#93)
1 parent3247e3d commit52205b2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

‎ClangFormat/TRVSFormatter.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ - (void)formatSelectedFiles {
8888
}
8989

9090
- (void)formatDocument:(IDESourceCodeDocument *)document {
91+
NSRect rect = [[TRVSXcodetextView]visibleRect];
92+
NSPoint containerOrigin = [[TRVSXcodetextView]textContainerOrigin];
93+
rect =NSOffsetRect(rect, -containerOrigin.x, -containerOrigin.y);
94+
NSRange glyphRange = [[[TRVSXcodetextView]layoutManager]
95+
glyphRangeForBoundingRect:rect
96+
inTextContainer:[[TRVSXcodetextView]textContainer]];
97+
NSRange charRange = [[[TRVSXcodetextView]layoutManager]
98+
characterRangeForGlyphRange:glyphRange
99+
actualGlyphRange:NULL];
100+
101+
91102
NSUInteger location = [[TRVSXcodetextView]selectedRange].location;
92103
NSUInteger length = [[documenttextStorage]length];
93104

@@ -102,13 +113,15 @@ - (void)formatDocument:(IDESourceCodeDocument *)document {
102113

103114
if (documentIsLongerAfterFormatting && location > diff) {
104115
location -= diff;
116+
charRange.length -= diff;
105117
}elseif (!documentIsLongerAfterFormatting) {
106118
location += diff;
119+
charRange.length += diff;
107120
}
108121

109122
NSRange range =NSMakeRange(location,0);
110123
[[TRVSXcodetextView]setSelectedRange:range];
111-
[[TRVSXcodetextView]scrollRangeToVisible:range];
124+
[[TRVSXcodetextView]scrollRangeToVisible:charRange];
112125
}
113126

114127
#pragma mark - Private

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp