Is it possible to move the text cursor/ caret multiple characters at once using C++? - operating-system

I'm writing an application that pastes strings into any given editor. After selecting something to paste my application programmatically looses focus, giving it to the application that had focus before. It then sends Ctrl+V to the OS to paste it in the other application. I want to be able to set the position of the cursor after pasting. Currently a pasted text will always leave the cursor at the end of the text.
I already tried sending multiple Arrow Left presses to the OS, so for example if I wanted:
Hello $CURSOR_POSITION$World
54321
I would send 5 times ArrowLeft after pasting "Hello World". This is very slow tho as every single Arrow Left key is processed serparetly (moves left about once per second). As the strings can get very long using Ctrl+ArrowLeft to skip entire words does not solve the problem.
I already looked into ANSI-Codes, they only seem to work in consoles though, I want it to work in every editor.
Is there a way to achieve this using C++? Something like moveCursorLeft(5)?
Thanks in advance!

Related

ms-word object model: custom spellchecking underlines

in making a MS Word add-in spellchecker, i'm faced with the issue of "underlines". I can use the formatting functions of the Word Object Model in order to color the misspelled words or to underline them just how a user would with the U button, but it's not the same as the native ms-word curly underline which doesn't show if you copy-paste the text elsewhere, doesn't get printed or saved and doesn't show in undo actions. I have been searching how to do it, but everyone keeps saying it's not possible.
There is this English spellchecker called Grammarly, they do have a ms-word add-in and they somehow underline the misspelled words (though it's not curly, just a straight thick line) and it works just like MS-Word:
a) it doesn't get copy-pasted when you move the text with the underlines elsewhere, nor does it gets saved when you save the document
b) it doesn't get added in the undo stack.
So from a) and b) I conclude that it's not text formatting
So there must be a way, I was wondering how can I achieve this.
Thank you in advance for any ideas or tips.
Unfortunately, MS Word doesn't provide out of the box functionality that would allow you to implement this. The way how Grammarly and other add-ons with similar functionality do it is they show the transparent window on top of MS Word window using Windows API. Then they identify coordinates of words that need to be highlighted and draw the highlighting (rectangles or underlines) inside of that transparent window on top of those words. This is not an easy solution because it requires to identify the visible range which is currently shown on the screen, find the words in that range that need to be highlighted and also track the user's actions such as scrolling and window resizing so that to redraw the highlighting after those actions. But for sure it's possible because we have recently done it in the product I'm working on. As far as I know, there is no ready open-source solution for this so you will need to implement everything yourself.
You may also consider a much easier solution which is highlighting the words using the Find.HitHighlight functionality. An example of how it works you can see when you search for a simple word in MS Word. Although this is not a very flexible solution because the only thing you can change is the color of the highlighting.
I believe the way Grammarly adds emphasis to words and phrases it wants to flag is to change the document temporarily in a very smart and controlled way. Grammarly only works when one clicks the Open Grammarly button on the Grammarly ribbon. If you do a simple experiment, you may be able to observe how Grammarly controls its temporary changes.
First create an unsaved document with some misspelled words that trigger Microsoft Word to display the wavy red lines. Then click the Open Grammarly button. Notice that the add-in turns off spell checking and replaces Word's wavy red lines with its own web-triggered markings. These are probably generated in the document using code similar to:
myRange.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineThick;
myRange.Font.UnderlineColor = Microsoft.Office.Interop.Word.WdColor.wdColorRed;
After observing this, save the document. If you look carefully at your screen (and if your computer is not super fast), you will see a small blink wherein the red thick underlines disappear for a brief moment. That is the Document.BeforeSave event removing the Grammarly markings before saving the document. By relying on user actions (such as when the user clicks the Grammarly ribbon button), Grammarly controls at what points in time the markings appear. It then uses code and events to make sure the markings are not saved with the document or interfere with other operations. The main events you would want to look at to replicate this behavior for your own spelling checker add-in would be:
Document.BeforeSave Event
Document.BeforePrint Event
Document.BeforeClose Event

Smart Caret in Eclipse stops working for some files

I am using Eclipse and I am coding java. I really like the "Smart Caret" option for the Home and End buttons since it allows you to go the start and end of a line but not past any whitespaces. Also the Home key will take you to the start of a comment, rather than the start of the line. And you can cycle through different positions with these keys. And this is how the editor was by default, from installation.
However one thing that has happened a few times now is that when I am writing code in the editor, this functionality just vanishes. It is seemingly random when it happens and the weirdest part, I think, is that it is file specific. So all of a sudden when I am writing, the Home and End keys start taking me to the very start and end of the line I am on. It is as if I am accidentally pressing some hotkey to disable these Smart Carets for the specific file.
It does not help to disable and re-enable the Smart Caret option in Preferences. And beyond that I do not really know what to do. Is this a bug? It is incredibly annoying when it happens. Being used to things working one way, then having them spontaneously change and then again having them back to the default when I am editing a different file.

Keyboard input blocks in VSCode

Since yesterday, I have a problem when want to edit code in VSCode. Apparently, after changing focus within VSCode, say switching to the menu bar or a to different view and then coming back to the editor view, the cursor changed from the caret to a filled rectangle, and normal keyboard input is blocked. I need to do something like pressing the Escape key which on the first, second, or third try finally puts me into overwrite mode from which I have to switch to insert mode. This is a very annoying situation. Does anyone have a remedy for this?
Apparently, I happened somehow to switch to the vim schema. Once I became aware of this, I simply switched back to the VS schema which I'm used to, and everything works as desired.

IE9 : Arrow Keys not working in text area field in popups

We are just testing our application on IE9 and I found an issue regarding the arrow keys behaviour in text area in popup window.
Two arrow keys are not working fine:
1) Left arrow key - When we enter some multiline text in the text field and try to move the left arrow key in last line. Repeated left arrows movement on the line result in the cursor going to the left THEN back to the end of the same line. It does not move to the last of the previous line (as expected).
2) Up Arrow Key - When we enter some multiline text in the text field and try to move to the previous line using the Up arrow key. It does not work.
It will be great if somebody can help me on it.
Thanks in Advance :).
Regards
I have seen many posts on this in other forums, and had some issues with it in web-based applications we use at my work. It seems to be something weird associated with IE9 and ieSpell.
While some forums have said pressing F7 allows you to get around the problem, it doesn't actually solve it, and there doesn't seem to be any acceptable permanent solution. Some say to dump your browsing history, others to turn caret browsing off in IE options.
Generally, there are lots of suggestions to get around the problem, but none to actually solve it.

Is there a way to mark specific lines in BBEdit and then iterate through them?

I often find myself jumping between several parts of a lengthy document, and I've found no streamlined way of handling this. I've previously used TextPad for PC, and it had a great feature called Bookmarks:
Press a keystroke, and the current line is marked. The bookmark shows as an arrow in the gutter.
The same key toggles the marker off again.
Another keystroke sends the caret down to the next bookmark.
Yet another keystroke sends the caret up to the previous bookmark.
Is there anything like this in BBEdit? I loved that feature of Textpad, but I haven't found another editor that has something similar. Currently I use the awkward substitute of typing three slashes /// at a place I want to jump back to, then using Ctrl+F to re-find them, but that's a lot of keystrokes to set/remove markers and to iterate through them.
Thanks!
I think what you are after is BBEdit Markers.
This article is a good place to start: macdrifter.com/2012/01/bbedit-markers.html