小编Luk*_*asz的帖子

如何让NSTextFinder显示出来

我有一个mac cocoa应用程序,其中包含一些包含一些文本的webview.我想使用NSTextFinder提供的默认查找栏搜索该文本.虽然这看起来很容易通过NSTextFinder类引用读取,但我无法显示查找栏.我错过了什么?

作为旁注:
- 是的,我尝试将findBarContainer设置为不同的视图,同样的事情.我回到滚动视图以消除调试的复杂性
- 调用performTextFinderAction来执行查找操作

**App Delegate:**

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

    self.textFinderController = [[NSTextFinder alloc] init];

    self.webView = [[STEWebView alloc] initWithFrame:CGRectMake(0, 0,  self.window.frame.size.width, 200)];
    [[self.window contentView] addSubview:self.webView];

    [self.textFinderController setClient:self.webView];
    [self.textFinderController setFindBarContainer:self.webView.enclosingScrollView];


    [[self.webView mainFrame] loadHTMLString:@"sample string" baseURL:NULL];

}

- (IBAction)performTextFinderAction:(id)sender {
    [self.textFinderController performAction:[sender tag]];
}

**STEWebView**

@interface STEWebView : WebView <NSTextFinderClient>

@end


@implementation STEWebView

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

    }

    return self;
}

- (void)drawRect:(NSRect)dirtyRect
{
    // Drawing code here.
}


- (NSUInteger) stringLength …
Run Code Online (Sandbox Code Playgroud)

macos cocoa objective-c

6
推荐指数
1
解决办法
2582
查看次数

如何在 contenteditable 中删除 HTML 元素时触发事件

我有一个内容可编辑的 div,其中包含一些 html 元素。例如,假设我有:

<div contenteditable="true" id="myTextArea">
   Some content, <div id="div1">content in div</div>, 
   and more <span id="span1">content</span></div>
Run Code Online (Sandbox Code Playgroud)

当用户在 myTextArea 中编辑文本并删除一些 html 元素(通过粘贴新内容或只是退格文本)时,我希望每个 html 元素触发一个事件并告诉我它已被删除。关于我如何做到这一点的任何想法?

html javascript events

5
推荐指数
1
解决办法
1189
查看次数

标签 统计

cocoa ×1

events ×1

html ×1

javascript ×1

macos ×1

objective-c ×1