G’day folks.
I thought I’d finished my App, but the latest Sierra has broken my Scroll Field scrolling.
The present script takes 1 minute to trim excessive paragraphs, and a whopping 10 minutes or more to simly scroll to the end.
Used to be lightning fast.
I’ve found this recommended method to now use, but canot work out how to re-write it for ASObC.
- (void)textDidEndEditing:(NSNotification *)notification {
NSTextView *text = [notification object];
unsigned whyEnd = [[[notification userInfo] objectForKey:@"NSTextMovement"] unsignedIntValue];
NSTextView *newKeyView = text;
// Unscroll the previous text.
[text scrollRangeToVisible:NSMakeRange(0, 0)];
if (whyEnd == NSTabTextMovement) {
newKeyView = (NSTextView *)[text nextKeyView];
} else if (whyEnd == NSBacktabTextMovement) {
newKeyView = (NSTextView *)[text previousKeyView];
}
// Set the new key view and select its whole contents.
[[text window] makeFirstResponder:newKeyView];
[newKeyView setSelectedRange:NSMakeRange(0, [[newKeyView textStorage] length])];
}
My old script is below, and the handler ’ScrollToEnd’ literally freezes on lines 2 & 3. Up to 15 minutes.
AnyBody kind enough to decipher the above, please?
As well, is there a faster way of removing excess lines from the top of the field, leaving the first 4 lines alone? (As in snippet below, which takes 1 minute)
Regards,
Santa
This takes 1 minute
if (my reDrawTheText) then
set p to 1
set (my theYear) to year of (current date)
set adjustRange to (((my clientMax as integer) * 10) + 5) as integer
set textStorage to mainMessagesView's textStorage()
set textStorageString to mainMessagesView's |string|()
set theRange to (count of (textStorageString's paragraphs)) as integer
set theOffset to (count of paragraph 1 of textStorageString) + (count of paragraph 2 of textStorageString) + (count of paragraph 3 of textStorageString) + 4
if theRange > (adjustRange + 40) then
set c to current date
set theCount to 0
try
set y to (theRange - adjustRange - 8)
if y > 14 then
repeat with x from 5 to y
try
set theCount to theCount + (count of characters of paragraph x of textStorageString) + 1
on error errmsg
if (my runForOz) then tell application "System Events" to display dialog errmsg giving up after 20
exit repeat
end try
end repeat
end if
end try
set textStorage to mainMessagesView's textStorage()
tell textStorage to replaceCharactersInRange:{theOffset, theCount} withString:""
set textStorageString to mainMessagesView's |string|() as text
set theRange to (count of (textStorageString's paragraphs)) as integer
end if
set textStorageString to mainMessagesView's |string|() as text
set theRange to (count of (textStorageString's paragraphs)) as integer
if theRange > adjustRange then
repeat
set textStorage to mainMessagesView's textStorage()
set textStorageString to mainMessagesView's |string|() as text
set theRange to (count of (textStorageString's paragraphs)) as integer
set textStorageLength to ((count of paragraph 5 of textStorageString) + 1) as integer
set theText to (paragraph 5 of textStorageString) as text
try
if ((word 1 of theText) as text) is in {"eMail", "ftp"} and theRange ≤ adjustRange then exit repeat
end try
tell textStorage to replaceCharactersInRange:{theOffset, textStorageLength} withString:""
end repeat
end if
This takes 10-15 minutes, for 2000 paragraphs
on scrollToEnd()
try
say 1
set textStorage to mainMessagesView's textStorage()
say 2
set newTextLength to textStorage's |length|() as integer
say 3
if newTextLength > 40 then mainMessagesView's scrollRangeToVisible:{location:newTextLength, |length|:0}
say 4
end try
end scrollToEnd
Model: late 2014 i7 iMac
AppleScript: 209 (191)
Browser: Safari 603.3.8
Operating System: Mac OS X (10.12.5)