All pastes #957957 Raw Edit

Stuff

public text v1 · immutable
#957957 ·published 2008-03-26 10:28 UTC
rendered paste body
	if([self isEditable])
	{
NSLog(@"editable\n");
		// Mail uses an editable WebView, in which case we want to send the entire page to the ODB Editor

		NSString* const CARET = [NSString stringWithFormat:@"%C", 0xFFFD];
		NSString* str = @"";
		int lineNumber = 0;

		DOMDocumentFragment* selection = [[self selectedDOMRange] cloneContents];
		if(!selection)
		{
NSLog(@"not sel");
			[self insertText:CARET]; // ugly hack, but we want to preserve the position of the caret
			[self selectAll:nil];
			selection = [[self selectedDOMRange] cloneContents];

			// remove the caret marker. TODO we should start an undo group, so the (chunked) undo doesn’t remove more than just the caret
			if(NSUndoManager* undoManager = [self undoManager])
			{
				if([undoManager canUndo])
				{
					[undoManager undo];
					[self selectAll:nil];
				}
			}
		}

		if(selection)
		{
NSLog(@"sel");
			str = convert_dom_to_text([[[self mainFrame] DOMDocument] createTreeWalker:selection :DOM_SHOW_ALL :nil :YES]);
NSLog(@"str %s\n", str);
			while([str hasSuffix:@"\n\n"])
				str = [str substringToIndex:[str length]-1];
NSLog(@"str %s\n", str);

			NSArray* split = [str componentsSeparatedByString:CARET];
			if([split count] == 2)
			{
				lineNumber = [[[split objectAtIndex:0] componentsSeparatedByString:@"\n"] count] - 1;
				str = [split componentsJoinedByString:@""];
			}
NSLog(@"str %s\n", str);
		}
		[EditInODBEditor externalEditString:str startingAtLine:lineNumber forView:self];
	}