Add loadHTMLString: API to HTML output view

This replaces the current HTML shown without adding to the history and will preserve scroll position.
This commit is contained in:
Allan Odgaard
2014-03-29 14:28:27 +07:00
parent a404daecce
commit b23163476f
3 changed files with 13 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ extern NSString* const kCommandRunnerURLScheme; // from HTMLOutput.h
@property (nonatomic) BOOL runningCommand;
@property (nonatomic) HOAutoScroll* autoScrollHelper;
@property (nonatomic) std::map<std::string, std::string> environment;
@property (nonatomic) NSRect pendingVisibleRect;
@end
@implementation OakHTMLOutputView
@@ -35,6 +36,12 @@ extern NSString* const kCommandRunnerURLScheme; // from HTMLOutput.h
[self.webView.mainFrame stopLoading];
}
- (void)loadHTMLString:(NSString*)someHTML
{
self.pendingVisibleRect = [[[[self.webView mainFrame] frameView] documentView] visibleRect];
[[self.webView mainFrame] loadHTMLString:someHTML baseURL:[NSURL fileURLWithPath:NSHomeDirectory()]];
}
// =======================
// = Frame Load Delegate =
// =======================
@@ -67,6 +74,10 @@ extern NSString* const kCommandRunnerURLScheme; // from HTMLOutput.h
if(frame == [sender mainFrame])
[self webView:sender didClearWindowObject:[frame windowObject] forFrame:frame];
if(!NSEqualRects(self.pendingVisibleRect, NSZeroRect))
[[[[self.webView mainFrame] frameView] documentView] scrollRectToVisible:self.pendingVisibleRect];
self.pendingVisibleRect = NSZeroRect;
[super webView:sender didFinishLoadForFrame:frame];
}