Komodo Edit macro to replace a specific word in current document with clipboard content; is it possible?

泪湿孤枕 提交于 2020-01-01 19:29:07

问题


I created this macro to replace a specific word with another word in the current document, but ideally, I want to replace it with clipboard content. My current code is as follows:

// Macro recorded on: Wed Jul 11 2012 01:29:42 GMT+0530 (India Standard Time)
komodo.assertMacroVersion(3);
if (komodo.view) { komodo.view.setFocus(); }
ko.find.replaceAllInMacro(window, 0, 'Itemlink', 'target', true, 0, 2, false, false);

The above code replaces the word 'Itemlink' with the word 'target', but how to use clipboard content instead ? So far, I found this Komodo command to paste data from the clipboard, but I don't know how to use it. The command is:

komodo.doCommand('cmd_paste');

Please help, thanks...


回答1:


Use a reference to the scimoz object, which uses a subset of the Scintilla API and includes both the copyText() method to add to the clipboard and the paste() method to output the current data:

komodo.assertMacroVersion(2);
var editor = ko.views.manager.currentView.scimoz;
editor.copyText(1,"("); //add left parentheses to clipboard buffer

Find_ReplaceAllInMacro(window, 0, 'Itemlink', editor.paste(), true, 0, 2, false, false);


来源:https://stackoverflow.com/questions/11421229/komodo-edit-macro-to-replace-a-specific-word-in-current-document-with-clipboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!