vscode - Is there a way to create an instance of `vscode.TextEditor`? - visual-studio-code

vscode - Is there a way to create an instance of `vscode.TextDocument`?
The question above except instead of textdocument I want for texteditor given the filepath.
Thanks in advance

No, there is not.
You can only show a TextDocument, using vscode.window.showTextDocument(someTextDocument, ...), where someTextDocument refers to some TextDocument instance, previously opened.
Hope this helps

Related

How to clear or change a message in Redis using powershell?

I am using powershell that is hooked up to jupyter redis rediscommander retwis
I am creating codes like hset snap:msg:4 to "che" from "Dax" text "Is this thing on?"
I made a mistake and msg:3 is meant to be msg:4. Is there any way to clear or edit this message?
Thanks
I have tried lpop but I am new to this and do not understand all the words and what they do yet.
Welcome to StackOverflow!
I made a mistake and msg:3 is meant to be msg:4. Is there any way to clear or edit this message?
You want to rename that key using the RENAME command:
RENAME snap:msg:3 snap:msg:4
How do I just clear everything?
If you wish to remove all the keys in the selected Redis database (caution!) you can do that with the FLUSHDB command. Alternatively, the FLUSHALL command removes all the keys from all the Redis databases (even more caution!).

Unable to Clear TextField in Appium Android Automation

I used the below code:
web.sendKeys(Keys.chord(Keys.CONTROL,"a"));
web.sendKeys(Keys.BACK_SPACE);
This method almost worked, it cleared first, and is entering an alphabet a, dont know y, I tried element.sendKeys(Keys.Delete); but still no luck, attached is the screen after the method was executed.
enter image description here
The clear function should provide what you're looking for:
element.clear()
Documentation on this can be found in the official Appium documentation.
element.clear() would work but if you actually need to delete something you can use exactly what you have except like this
web.sendKeys(Keys.chord(Keys.CONTROL,"a"));
web.sendKeys(Keys.BACKSPACE);
no _ in BACKSPACE
keep in mind if you want to delete a characters before the cursor use Keys.BACKSPACE, to delete characters after the curser use Keys.DELETE

In a VS Code extension, how can I be notified when the user cuts/copies/or pastes?

For my extension I need to know when a cut/copy/paste happens and be able to get the text associated with those operations. I can probably get the text from the editor if I know when they happen.
I cannot find a listener for these operations. I suppose I can look for ctrl-x, ctrl-c, and ctrl-v keyboard inputs but some users may use the edit menu and not use the keyboard.
Is there a way to be notified when these operations happen either from the keyboard or the edit menu?
Original asker here...
I came up with a solution that involves overriding the default cut/copy/paste actions in the editor. Here is the code for 'copy' in extension.js (I am using js not ts):
//override the editor.action.clipboardCopyAction with our own
var clipboardCopyDisposable = vscode.commands.registerTextEditorCommand('editor.action.clipboardCopyAction', overriddenClipboardCopyAction);
context.subscriptions.push(clipboardCopyDisposable);
/*
* Function that overrides the default copy behavior. We get the selection and use it, dispose of this registered
* command (returning to the default editor.action.clipboardCopyAction), invoke the default one, and then re-register it after the default completes
*/
function overriddenClipboardCopyAction(textEditor, edit, params) {
//debug
console.log("---COPY TEST---");
//use the selected text that is being copied here
getCurrentSelectionEvents(); //not shown for brevity
//dispose of the overridden editor.action.clipboardCopyAction- back to default copy behavior
clipboardCopyDisposable.dispose();
//execute the default editor.action.clipboardCopyAction to copy
vscode.commands.executeCommand("editor.action.clipboardCopyAction").then(function(){
console.log("After Copy");
//add the overridden editor.action.clipboardCopyAction back
clipboardCopyDisposable = vscode.commands.registerTextEditorCommand('editor.action.clipboardCopyAction', overriddenClipboardCopyAction);
context.subscriptions.push(clipboardCopyDisposable);
});
}
This definitely doesn't feel like the best solution... however it does seem to work. Any comments/suggestions? Are there any issues that repeatedly registering and unregistering will cause?
There is no api to access the clipboard directly but some extensions override the default copy and paste shortcuts to customize the copy paste behavior. Here are two examples:
https://github.com/aefernandes/vscode-clipboard-history-extension/blob/master/src/clipboard.ts
https://github.com/stef-levesque/vscode-multiclip/blob/master/src/extension.ts
As you note, that approach will not work when copying using the context menu however. For supporting that as well, you could try intercepting the editor.action.clipboardCopyAction command. See how the Vim extension intercepts the type command for an example of this: https://github.com/VSCodeVim/Vim/blob/aa8d9549ac0d31b393a9346788f9a9a93187c222/extension.ts#L208
There is a proposed api in v1.68 for intercepting and modifying pastes. Since it is proposed for now you can only test it in the Insiders Build.
See copy/paste proposed extension api:
The new documentPaste API proposal lets extensions hook into copy
and paste inside text editors. This can be used to modify the text
that is inserted on paste. Your extension can also store metadata when
text copy and use this metadata when pasting (for example for bringing
along imports when pasting between two code files).
The document paste extension
sample
shows this API in action: <-long code example in the release notes->
Here is the actual (brief) api: proposed documentPaste api
See also using a proposed api

Outlook meetings and rich text format

I have been working on creating appointments from Powershell in Outlook. Everything seems to be working with the exception of being able to set the appointment.RTFBODY. It looks like it is stored as a byte array, but despite my best efforts and many attempts I have been unable to set it. Any suggestions would be much appreciated.
http://pastebin.com/kQvGfNRS
Edit: I was able to find what could be a similar issue. https://social.msdn.microsoft.com/Forums/sqlserver/en-US/5dba0d12-94e8-47a5-b082-93d3693e2a47/cant-set-the-rtfbody-of-an-appointmentitem
"I assume you add a wrong version reference. If you add Microsoft.Office.Interop.Outlook 12.0, I could reproduce your issue. I suggest you remove this reference, and add Microsoft.Office.Interop.Outlook 14.0."
Also found this: Outlook AppointmentItem - How do I programmatically add RTF to its Body?
from the link in your question - "it is just a known problem in OOM - setting the RtfBody property using early binding works. Setting through IDispatch::GetIDsIfNames / Invoke does not."
Powershell always uses late bindings (i.e. you cannot declare a variable as an instance of a particular object. e.g. AppointmentItem).

WebDriver and GWT Suggest Boxes

Ok...I give up :)
What is the best way to select values out of a GWT Suggest Box using
WebDriver? I'm using FirefoxDriver, and so far nothing seems to pick
values out of a GWT suggestBox...not sendKeys, not selenium.keyUp,
anything.
I've even tried executing javascript directly to get those values to populate, like this (to no avail):
((JavascriptExecutor) driver).executeScript("document.getElementById('spSelect').value='verizon'");
Is there a better
way? If not, what is the "best" way to get values out of a GWT suggest
Box?
Many thanks in advance.
Cheers
Pedro
Ok, we've figured out our problem.
We were setting explicit IDs on our elements, so our tests can grab
them easier. In GWT this is done via:
usernameLabel.getElement().setId("consoleLoginPageUserNameInput");
This works fine for most GWT inputs, but for the SuggestBox it is
handled a bit differently:
spSelect.getElement().getElementsByTagName("input").getItem(0).setId("spSelect");
After grabbing the correct inner table, we are able to interact with
this input with Selenium just fine. Hope this helps someone.
Cheers
Pedro
Try this javascript (from here):
To set the value:
document.getElementById("spSelect")["value"] = "verizon"
To retrieve it:
var value = document.getElementById("spSelect")["value"];