I want to display a form at the current caret position in Microsoft word 2007 addin. I can easily find the mouse Cursor position using Cursor class. However I couldn't find a way to get the position of Caret. Is there a way to find the position in Point.
The Word object model provides the Information property which provides the cursor position information. You just need to pass the WdInformation enum value to get the required data.
Related
Situation:
I am crating an console application for windows using rust. Fore that I use winapi and kernel32.
Lets say my cursor position within the console is at 4,4 (X,Y) then I print an character like print!("#"); at position 4,4. Then the console automatically moves the cursor one to the right 5,4 for the next character to be printed there.
Question
Is it possible to prevent this default behavior, and have the cursor stay at 4,4 instead of moving to the next cell, usingwinapi/kernel32? What I mean by that is that the console should not change cursor position in any case until I manually tell the console to change the cursor position to another cell.
Example or solution maybe in any language.
Is there a way to get the cursor position (not the row and column) in Ace Editor.
For example, if the contents of the Ace Editor are the following:
Hello
World
And the cursor was after the "Wo" in "World". The position or index would be 7 or 8 (if you count newline).
Is there a method to get the position?
Ace calls {row, column} objects position, and the number of characters since the document start index.
You can convert position to index using editor.session.doc.positionToIndex method https://github.com/ajaxorg/ace/blob/v1.2.6/lib/ace/document.js#L678, but note that this method is not very fast since it has to iterate over the whole document, so use it and indexToPosition as sparingly as possible.
I'm using Ace editor and I'm using the search and as I use it it is searching through the document on each key press change.
So what I mean is as I type into my search box I'm calling this method on each text change:
editor.find(searchInput.text);
If I have a document with ten items named "list" and I type "L" it finds the first instance and highlights "L". Then I type "i" and it finds the second instance and highlights "Li". Then I type "s" and it finds the third instance and "Lis" is highlighted.
What I'd like it to do is stay on the first instance and highlight "Lis". I think I need to set the cursor position. But how do I get the cursor position of the beginning of the highlighted word? Or better yet is it possible to continue subsequent calls to find() starting at the current search position? I hope this makes sense.
There is a skipCrrent option for search see https://github.com/ajaxorg/ace/blob/v1.2.0/lib/ace/ext/searchbox.js#L220 which is from built in ace search which already works as you describe
It looks like I can ensure the search continues from the current anchor position by using the following code:
var position = editor.getSelectionAnchor();
editor.find("needle", {row:position.row, column:position.column});
FYI It did not seem to work with integers but I could be wrong (try casting to string).
As suggested by #auser, setting skipCurrent to false works as well.
editor.find("needle", {skipCurrent:false});
I am currently developing a Visual Studio extension, that needs to open a WPF form after firing a menuCommand.
I want to open the form relativly to the caret position, so I need to get the Caret's pixel position.
I've checked This article
but it didn't work.
Help please?
Once you've got a IWpfTextView, you can do view.TextViewLines.GetCaretBounds(view.Caret.Position.BufferPosition) which will give you the position in the "text coordinate system". Adjusting by view.ViewportTop/view.ViewportLeft should give you the position relative to the UIElement that is the view. From there, view.VisualElement.PointToScreen will probably get it to screen coordinates.
I assume you're already figured out that you don't want to embed this UI into the editor directly? Because that's (mildly) easier.
As a preface I'm using ViEmu although I dont think this affects anything. I would simply like to scroll up in the Text Editor along with moving the cursor to the relative screen position.
As an example, if my text editor displays 100 lines of viewable code (1 - 100) and my cursor is on line 20, when I scroll down to the next viewable 100 lines (101 -200) I would like the cursor to be at 120.
Using the VS command Edit.ScrollDown scrolls the code down as expected but leaving the cursor at line 20 instead of moving it to 120. Is there another command to use or any way to alter this behavior?
As noted in the question you seem to be wanting to re-map Page Down to another key (due to limited keyboard).
To identify which command a key is mapped to open the keyboard customisation dialogue and type in the current key into the short key text box and then look at what it is currently mapped to.
Unfortunately this doesn't work for page down (control-page down does work, but that doesn't help here).
Entering "page" into the command filter does: Edit.PageDown is mapped to Page Down in the text editor. Map this command to another shortcut.