How to manipulate the contents of CEdit? - winapi

I have a situation with edit control and I need some guidance. The text editor functions normally in most cases but in other cases, depending on the last few characters before typing and based on the characters typed, the last few characters must be replaced with different characters.
The solution that looks obvious to me is to have a character buffer, GetWindowText() just before the contents are changed, add the characters typed into the buffer, manipulate the buffer if necessary and then SetWimdowText().
I know the edit control has its own buffer. So is this the right approach to have my own buffer or are there ways I can share the buffer with it etc? The editor might not have more than 4MB worth of characters.
I need this to work on Windows 7 and XP, not keen on older ones.I use MFC.
Thanks for your help.

You don't need your own buffer and indeed it would be dangerous to have one since it will likely get out of synchronisation.
But you don't need to set the entire edit text at once. From the documentation:
Also, if an edit control is multiline, get and set part of the control's text by calling the CEdit member functions GetLine, SetSel, GetSel, and ReplaceSel.
ReplaceSel is what you are looking for I think. Although this text talks about multiline edit controls, SetSel, ReplaceSel etc. work fine with single line edit controls.

Related

show/hide characters on CKEditor

Can someone help? I've googled it a lot and couldn't find an answer. Is there a way to show/hide non-printable characters on the CKEditor, like there is on word? I couldn't find any plugin for it :/
In short, there is no way to do it or at least it is not easy.
Now the longer version. If you are talking about the Pilcrow character then it is possible to show it in CKEditor by using HTML entities ¶ or ¶ but please note this character is NOT non-printable by any means and in order to make it non-printable you would need to write a code which handles it and this is not easy. First of all you would need write a code (can be done as CKEditor plugin) which inserts Pilcrows on Enter and removes them wherever data is sent to server. So far so good but since this is a normal character (from CKEditor content area POV) you would need to handle all situations in which this character can be removed while typing, styling and modifying entered text and this is next to impossible.
As an alternative you could try having a code which inserts e.g. spans with PilcRow as a background image. While it would be easier to handle spans than plain character you would still need to handle all situations in which this span should or should not be removed while typing, deleting text, styling etc. and again this is very hard to do.

Convert tab to spaces

Usually we replace tabs to spaces in editors while coding.
What is the exact need for that?
Is it for because the OS handles \t in the files?
I am really not very sure of this. Kindly clarify
Tabs don't have fixed width, its width depends on IDE (editor) settings. It is usually set to have width 4 spaces, but it doesn't have to be. There probably wouldn' be any problem if you use only tabs and don't use spaces, but this will never happen. You can bet, you will always want to move some text by only one extra space to the right. Then you will be mixing spaces and tabs together and that's what brings trouble. It might look correct in your IDE, but then you will want to do some change in vim editor for example, where there will be different tab size set. Indentation of the code won't be what would you expect. Also when you send some code to your co-worker, he might use different IDE with different settings and he will again see wrongly aligned code. On the other hand with spaces only you see what see the others.

Smart indent effect on completion (intelliSense) sessions

I am writing a Visual Studio extension which provides intelliSense for a certain content type.
The problem that I am facing now is the effect of "Auto Indent" that Visual Studio provides on empty lines when user types a character.
Here a completion session started on an empty line (over virtual spaces):
Notice the tab symbols on the other lines and no tab on the line with caret on it.
Now when use starts typing, VS automatically and correctly adds necessary tab characters to the line:
Now the problem is those Added tabs apparently become part of the user input and as a result CurrentSession.SelectedCompletionSet.SelectBestMatch() or Filter() method cannot find the current item which starts with "C" here (thinking user has typed \t\tC instead).
If I start the session on anywhere else which does not require auto indent everything works fine.
Any idea?
Edit (more information): I used a code flow very similar to:
Ook here
vsLua here
vsClojure here
In Lua and Clojure you wouldn't face this problem because they never provide intelliSense on virtual spaces (meaning they always start after a certain set of characters) and if you start after a character virtual spaces are already turned into real spaces.
Ook on the other had has the same problem.
Revised Answer:
Ah, I see. I interpreted your question thinking that you were referring to completion triggering via typing, not from the explicit command. If you enable "show whitespace" for the C# editor, you can see what we do here: when you trigger the "show completion" command, we explicitly realize the whitespace so you're no longer floating around in virtual space. You should probably do this as well. (Alternatively, you could detect the scenario and fix it up on the first typing by adjusting your ApplicableTo span, but that's probably not worth the trouble.)
You can get the whitespace that should be inserted from IEditorOperations. So MEF import an IEditorOperationsFactoryService, and then do:
var editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
var whitespace = editorOperations.GetWhitespaceForVirtualSpace(textView.Caret.Position.VirtualBufferPosition);
if (whitespace.Length != 0)
{
textView.TextBuffer.Insert(textView.Caret.Position.BufferPosition, whitespace);
}
(Funny aside: as I answered this, I was curious to see how we handled this in the Roslyn C# and VB editors. The answer was "not", but filtering still worked by pure luck later in the code.)
Original Answer:
I suspect by your description of the problem that you are implementing your completion like this: you know a character is about to be typed (either via a keyboard filter or IOleCommandTarget) and you trigger an ICompletionSession, where the tracking span is an empty span on the current caret position.
The best approach to fixing this is to not trigger the session before the key is pressed and goes into the editor, but rather after it. This is what we do in the Roslyn implementation for C# and VB completion. Then, when you are in your AugmentCompletionSession call and creating your CompletionSet, compute the "applicable to" span which consists of the non-whitespace characters around your caret. The easiest way to compute this might just be to call GetWordExtent from the text structure navigator.
This allows for other scenarios to work right. Consider scenarios where the user types C, presses escape, and then continues to type your identifier. If you want to trigger completion again, you'd have to do the math to ensure that the "C" is counted as part of your span anyways.

Control Characters and How OS/TextEditors interprets them?

I was going thru some content about control characters especially newline character(will focus on this).After going thru
http://en.wikipedia.org/wiki/Control_characters, got to know that \n is the line character in unix
while it is \r\n in windows. Now i got the question how OS comes into picture when iterpreting
ASCII Codes becoz i was under impression when we type any given character on keyboard, any OS send the same
bits and editor interprets that bit and display the corresponding character. Looks like this understanding is
wrong, Because different bit is sent in case of unix(\n) and windows(\r\n) when we press ENTER(new line terminator).As per
new understanding if we press ENTER on diff OS(say unix and windows),different bits are sent to editor and its
responsibilty of text editor to show the typed stuff in new line keeping the underlying OS in picture.Please let me
know if my understanding is correct as this will help me to understand other basics also?
Next question is if above is correct, what can be the reason different OS treat some control characters differently
when they treat all other characters equally? Is it becoz specific bits are already reserved in specific OS?
How an application treats keyboard input varies a bit, actually. When you press return the application is under no obligation to actually generate LF or CR+LF anywhere. E.g. it might decide to just end the current paragraph object and start a new one (e.g. in a word processor). If it's a Windows text editor then it will probably just write CR+LF into the file, while on Unix it just writes an LF.
They keyboard itself is very, very far removed from things you see on the screen or even on the disk. This goes through scan codes, keyboard layouts and other transformations before it ends up as text or markup somewhere.

Windows text editor that shows/hides lines based on RegEx or Grep syntax?

One of my application components produces some extremely hairy log files. They require a lot of poking and prodding before they produce useful information. I'm on the hunt for a text editor for windows that will let me enter text in either RegEx or Grep-style syntax, and automatically show/hide the relevant lines.
Does anyone know of a text editor that has this feature?
Thanks!
IVR Avenger
I know it's answered already, but http://glogg.bonnefon.org/ is the perfect answer for this. Couldn't live w/o it.
I would recommend Notepad++ as far as a good all-around Windows text editor is concerned - it is very extensible and includes just about every power feature you need to wade through data logs. If your log files are in a well-defined format, you can even use the built-in language editor to define a custom visual scheme for your logs - easier on the eyes.
-matt
GVim with for example, :g command. There are also plugins that allow entering search criteria, and they show relevant lines, and fold everything else.
Emacs, of course (occur), but I think pretty much every editor will do this.
Another option is SlickEdit using it's "Selective Display..." option
Although it wont show/hide based on a regex, Textpad will allow you to search and produce a hyperlinked result file with the lines that will allow you to click into the actual log. Consider the benefit: You can keep the filtered results up on your left monitor, and you can click into the full files and show them on your right monitor to see the context.
SPFLite is free and does just what you want. At least the IBM SPF and ISFP (used on IBM mainframes as part of the MVS operating system) that it emulates is just what you want.
From what I have tried, SPFLite will probably do the job. It can X (exclude) all lines from view, or eXclude lines with a given character or phrase (optionally starting in a certain column) from view. Or after eXcluding all lines, you can display, by Finding, characters or strings (optionally starting in a certain column). I think it also has a macro capability. The original does, and I think this Lite does as well. How robust I do not know. The original could create interactive screens and programs using the MVS TSO Command Language.
I found SPFLite at http://www.spflite.com/
I found that this interface is not so easy to use, but one gets used to about anything if necessary.

Resources