How to enable Virtual Space in AvalonEdit? - c#

I want to achieve "Virtual Space" functionality, similar to one in Visual Studio, in AvalonEdit.
I.e. the caret could be positioned beyond the end of the text line, and if you press any key, there would be spaces automatically added to match.
I am very used to this feature, but neither Googling nor studying AvalonEdit's code gave me any clues on how to enable it, if it is supported at all.
If it is not, suggestions how to extend caret handling mechanisms would be nice.
Thanks!

Edit:
Virtual space support has been added to AvalonEdit in version 4.2.0.8283.
Set textEditor.Options.EnableVirtualSpace = true;.
Below is my original answer.
It's not currently supported.
If you want to try adding it, make sure you read the "coordinate systems" documentation (in the help file on CodeProject). You'll want to extend the "visual column" so that positions after the line end are valid. And you'll have to adjust the position<->column calculations (VisualLine.GetVisualColumn and friends). Use TextView.WideSpaceWidth to figure out the columns past the end of the line.
The above should allow you to use the mouse to place the caret in virtual space. After that, you'll need to change the caret movement (arrow keys, CaretNavigationCommandHandler) and text input logic (TextArea.PerformTextInput) to also support the virtual space.
And if you're successful with the above steps, don't forget to contribute your changes back to AvalonEdit. :-)
While I'm not a fan of virtual space myself, we need something like it to make the RectangleSelection work properly.

Related

VS IDE setting, for more code real estate

So here's the issue, i've removed just about everything i've found in the program- but i can not figure out for the life of me how to remove the useless whitespace that was where the line numbers were, which is completely irrelevant to me, you are basically losing 1/8th of the entire screen to useless whitespace in this IDE, and i'd like to remove it, but i dont see a setting for it, does anyone know where it is ? - basically you can see on the red lines what i mean to remove, also does anybody know how to remove the blue little extra bar? Also useless to me. Thankyou to whoever can point me to a setting where i can switch off this and retrieve some of my lost screen real-estate.
That area is for the Intellisense "Hint" icon, the track changes, selection margin, and indicator margin. Those settings are found by opening Tools > Options > Text Editor > General:
Here is what my IDE looked like before deselecting them:
And then after:

How to fix rectangle height in Reportviewer Visual Studio

I am working with Visual Studio 2010 ReportViewer WinForms.
I have been unable to figure out how to fix the rectangle height in a report. I've tried using a table within the rectangle, also a table in a sub report that is placed in the rectangle of the main report with no success.
Basically, I am setting up an invoice-type report that must keep its' form and should not be allowed to grow so that elements are pushed onto a second page.
Both rectangle and tables will always grow vertically based on the content. There is no way to really stop this.
There are a couple of properties that might be able to help you get the correct page breaking in place:
KeepTogether indicates whether to keep all sections of the data region together on pane page.
When set on true and the region is to large to fit the page, this will add a page-break before the start of the region to try and fit as much as possible on a single page.
So if you wish for the region to start at the initial location but break afterwards, make sure this is to false.
PageBreak has the parameter BreakLocation which can be used to determine a fixed place to add a page-break. You can set it on Start, End, StartAndEnd or Between.
You could split your report in fixed pages and use these to add standard page-breaks in the desired (fixed) locations.
These properties alone might not be enough to get your desired result. Especially when working with tables it is hard to add a page-break after a fixed amount of rows.
It is hard to give you a detailed description of a possible approach with the amount of information you gave me, but here is some general advice.
You should split your data in the correct intervals before sending the datasource to the reporter. You can for example use grouping to place them in the correct intervals and add page-breaks based on the grouping.
Another solution is to add them in separate containers, this will require you to have enough spare data regions at your disposal. If there are too many you can always hide the empty ones based on an expression set for the Hidden property.
It won't be easy to set this up correctly so that it can dynamically grow. It takes a lot of puzzling from your end but pretty much any layout should be possible to achieve.
I wish I could give you a more specific solution to your problem and am willing to help you further if you give me an example to work with. But ultimately this is something you should be able to achieve on your own.

Pattern tracing app for Windows store

I'm currently working on an educational Windows store app in which the user will be able to trace over letters (e.g., A, B, C, but not limited to English) to learn the basics of writing.
How can I detect input and then compare it to an image mask of a letter using C# and XAML?
To do this you will need to have some way to rasterize your text that you want the user to trace over. Then, in order to provide feedback on whether they traced it correctly you'll need to continuously listen for the draw event and compare the input to what they should be drawing.
Basically, if a user draws a certain path or set of paths on a canvas, you'll want to be able to provide instant feedback on if they got it right yet. To give you some direction for this, I recommend you read this answer on SO, which roughly describes how to capture input and draw it on a canvas.
From there you should be thinking in terms of matching the user's input to an image of the letter they're supposed to be drawing. This requires some amount of image matching. To get you started, I recommend reading through all the answers to this post on SO.
Since you seem to be lacking direction in general, here's an idea of how your program could be structured:
Load the current letter to be drawn, and make sure to perform the appropriate calculations to pre-determine as much as possible for comparing to the input. Based on the second link above, this means you should call GetPixel for the letter to be drawn before the user is allowed to start tracing it (also note that you may want to downscale the image for better performance). You will also need to decide what your match threshold will be. Try starting with something like 70%.
Capture the user's input on a canvas, as explained in the first link. You'll probably want to adjust the brush width, but that post is a great start.
In the MouseMove event, you will also want to occasionally check to see how well it matches with the letter they're supposed to be drawing.
Once the user's input is within your match threshold, move on to the next letter. You may want to consider providing them with how well they did, based on the match percentage.
Experiment with values such as the brush width, image resolution, and how often you compare the input to the letter. Also try to do as much of the image processing as you can while displaying a 'loading' prompt when moving to the next letter to be drawn.

Scrolling through Visual Studio Intellisense list without mouse or keyboard arrows

I'm a heavy user of Intellisense in Visual Studio. I'm also a "keep your hands on the keyboard" and "keep them in home position" aficionado, so I'm always looking for ways to keep my hands centered on the ASDF JKL; keys as much as possible.
Whenever the Intellisense list pops up in Visual Studio, if there are many words in the list that start with the same letters as the word I'm trying to select, typing the first few letters to hone in on my selection doesn't help, since the list won't jump down to my preferred selection until I type enough characters to finally reach the first unique character in the word. It's usually faster to take my right hand off the JKL; keys and reach for the up/down arrow keys to manually scroll through the list.
I'd rather keep my hands centered in home position, and ideally use something like the J and K keys to move up and down in the Intellisense list (similar to how J and K move up and down in Vim...and especially since I use VsVim inside Visual Studio).
The MSDN Intellisense documentation only lists the up/down arrow keys and scrolling (mouse wheel, PgUp/PgDn keys, etc.) as options for doing this:
So here are my questions (in order of preference):
Are there any existing keyboard shortcuts in Visual Studio that allow keeping your hands in home position while scrolling the Intellisense list?
Is there any way to custom map keyboard keys (such as J and K) to do the up/down scrolling in the Intellisense list?
Are there any plugins that enable this functionality?
Is there any other way to accomplish this?
I have remapped CTRL+P to Edit.LineUp and CTRL+N to Edit.LineDown and this works in the Intellisense dropdown. For some reason the Intellisense dropdown dims out when pressing CTRL so it gets kind of hard to see the content in the dropdown. It's not a big problem though, since you can always release CTRL and it will light up again. I mostly use this method when I don't know the name of the method and want to browse for it.
If I know the name or part of the name it is often quicker to just type some of the letters in the method name. If I know for example that the name of the method I want is GetHashCode then I would just type "geh" or "has" or similar since that would be matched by intellisense.
Go get a used Kinect for $30 and map either a voice command or a head gesture to mouse scroll event. The SDK is really easy to use. You could say if head tilt left scroll up or right scroll down.
SDK
http://www.microsoft.com/en-us/kinectforwindows/develop/developer-downloads.aspx
Documentation
http://www.microsoft.com/en-us/kinectforwindows/develop/learn.aspx
Example Projects
http://channel9.msdn.com/coding4fun/kinect
You're only limited by your imagination.
I'm not sure which keyboard you prefer to use, but would an option be getting a keyboard with a thumb-accessible scroll wheel? Or something like the Microsoft Natural Ergonomic 4000, which is a pretty great keyboard on its own but has a zoom-slider that's accessible to your index fingers on the home row. With some work you can change the zoom functionality to scrollup and scrolldown.
I was looking to accomplish the same that Doktorn suggested in Visual Studio Code, so I will put the solution here just in case someone needs the same.
You have to add two new Key bindings in keybindings.json:
[
{ "key": "alt+j", "command": "selectPrevSuggestion",
"when": "suggestWidgetVisible" },
{ "key": "alt+k", "command": "selectNextSuggestion",
"when": "suggestWidgetVisible" }
]
This method is working in VSCode for Windows 10, latest version. Works just like up and down arrows.
{
"key": "alt+j",
"command": "selectNextSuggestion",
"when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
},
{
"key": "alt+k",
"command": "selectPrevSuggestion",
"when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
}
This!
When my hands leave the keyboard, 90% of the time it's for the arrow keys, often to accept an intellisense suggestion.
So Autohotkey. The script below gives me arrow keys that work the same in all applications! I put them on the top row, right hand to minimise collisions while still being ergonomic. One script does the same thing in SSMS, Visual and Visual Code, and everything else.
ctrlu up
ctrli down
ctrlo left
ctrlp right
Works like a charm. This has become absolutely fundamental for me. The only friction is that by default it will run with normal privileges, so it won't be available in programs you launch as administrator. If you want, set autohotkey to run as administrator. You will have a UAC prompt every time it starts, but you'll have your arrow keys all the time. Autohotkey intercepts the key combos before the app gets them, so you will lose app shortcuts mapped to these keys. In VS Code, ctrlp is essential, but ctrle does the same thing. ctrlp is Print in many other apps, but when was the last time you printed anything?
# ArrowKeys.ahk
^u::
Send,{up}
Return
^i::
Send,{down}
Return
^o::
Send,{left}
Return
^p::
Send,{right}
Return

RichTextBox losing selection/caret position when changing underlying's FlowDocument's text

I've implemented "ChangeCase" keyboard shortcut (like Shift+F3 in MS WORD) for RichTextBox, which changes the text either selected by mouse, or the last word before caret's position. The problem is, it SOMETIMES loses the selection, or moves the caret one word left.
Once it changes the textcase without this changing of caret position, then it never changes the caret position (propably some WPF's internal caching.), so it can only happen the first time i run this function to a portion of text.
The code used is the solution mentioned in here WPF Flowdocument "change case" feature .
One problematic section of code is certainly
end = this.CaretPosition;
EditingCommands.MoveLeftByWord.Execute(null, this);
start = this.CaretPosition;
this.CaretPosition = end;
However I have no idea why it only occurs sometimes and how to fix this.
I thing it has something to do with the execution speed of this Execute() method and some side effects, because at my WPF app it only happens sometimes, but when hosting this WPF control in Winforms, moving the caret one word left happens all the time (if I hold Shift+F3, the cursor moves word by word to the very beginning of the document)
Other problem can be related with changing text of a TextRange, which is resulting in losing the selection? But again, it doesnt happen all the time and I have no clue how to fix it.
Any ideas?
I ended up with 2 options, ignoring this error or implementing the
MoveLeftByWord
logic manully without touching the
CaretPosition

Categories