Skip to content

Commit

Permalink
Set line number correctly for textareas
Browse files Browse the repository at this point in the history
Previously when editing a textarea, the line number was always set
to zero (the first line). We now count the line numbers correctly so that
the caret appears on the correct line within TextMate.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>


git-svn-id: http://svn.textmate.org/trunk/Tools/Edit%20in%20TextMate@8983 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information
sorbits committed Feb 22, 2008
1 parent c39d506 commit b850407
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/WebView: Edit in TextMate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,20 @@ - (void)editInTextMate:(id)sender
{
// Likely the user wants to edit just a text area, so let’s try to find which
if(DOMHTMLTextAreaElement* textArea = find_active_text_area(self))
[EditInTextMate externalEditString:[textArea value] startingAtLine:0 forView:self]; // TODO calculate the line number from selectionStart
{
NSString* str = [textArea value];
unsigned long selectionStart = [textArea selectionStart];
int lineNumber = 0;
NSRange range = NSMakeRange(0, 0);
do {
NSRange oldRange = range;
range = [str lineRangeForRange:NSMakeRange(NSMaxRange(range), 0)];
if(NSMaxRange(oldRange) == NSMaxRange(range) || selectionStart < NSMaxRange(range))
break;
lineNumber++;
} while(true);
[EditInTextMate externalEditString:str startingAtLine:lineNumber forView:self];
}
else NSBeep();
}
}
Expand Down

0 comments on commit b850407

Please sign in to comment.