This is a migrated thread and some comments may be shown as answers.

Shift + Backspace doesn't do anything (should do what normal backspace does)

9 Answers 159 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Bryce
Top achievements
Rank 1
Bryce asked on 12 Apr 2012, 06:53 PM
Hi,

I know this is a weird question, but someone who uses the application I made gets annoyed by the fact Shift + Backspace doesn't do anything. What it usually does is just backspace (and yes I have said why don't you just use backspace). I noticed the normal textbox has this functionality. Is there any way around this?

Thanks,
Bryce 

9 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 17 Apr 2012, 11:06 AM
Hi Bryce,

 You can read the following article and see how to create your custom bindings.
 Here is how you can add the desired combination you mentioned:

<telerik:RadRichTextBox Name="radRichTextBox1" >
    <telerik:CommandManager.InputBindings>
        <telerik:InputBindingCollection>
            <telerik:KeyBinding Gesture="Shift+Back" Command="RichTextBoxCommands.Delete" CommandParameter="true"/>
        </telerik:InputBindingCollection>
    </telerik:CommandManager.InputBindings>
</telerik:RadRichTextBox>


If you have any other difficulties, contact us again. Regards,
Martin
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Oleg
Top achievements
Rank 1
answered on 17 Jan 2013, 02:22 PM
Hey there!

I have a question too - how can I make "CTRL + BACK" delete the whole word to the left from the current caret position? This feature is in mostly all editors - it deletes everything until it comes over a space or a comma or something like that. Is there a easy way to enable it?
0
Boby
Telerik team
answered on 18 Jan 2013, 08:08 AM
Hello Oleg,
This feature is in our to-do list, but for now it's not sure if and when it will be implemented.

Greetings,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
danparker276
Top achievements
Rank 2
answered on 15 Jul 2013, 11:23 PM
I would also be interested in the ctrl-backspace feature.  No one is going to be writing LOB applications in Windows 8 metro.  It'll be 10 years before any IT guy installs Windows 8 at any of my client sites.  Is there a place we can vote on this feature?
0
Oleg
Top achievements
Rank 1
answered on 16 Jul 2013, 07:23 AM

I wrote this custom Event handler, to Support common stuff like ctrl+home, ctrl+end, ctrl+delete and ctrl+backspace commands.
Hope it helps.

private void Editor_PreviewEditorKeyDown(object sender, Telerik.Windows.Documents.PreviewEditorKeyEventArgs e)
        {
            if (e.Key == Key.Home && Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
            {
                DocumentPosition startPosition = Editor.Document.CaretPosition;
                DocumentPosition endPosition = new DocumentPosition(startPosition);
                startPosition.MoveToFirstPositionInDocument();
 
                if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
                {
                     Editor.Document.Selection.AddSelectionStart(startPosition);
                     Editor.Document.Selection.AddSelectionEnd(endPosition);
                }
            }
            else if (e.Key == Key.End && Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
            {
                DocumentPosition startPosition = Editor.Document.CaretPosition;
                DocumentPosition endPosition = new DocumentPosition(startPosition);
                startPosition.MoveToLastPositionInDocument();
 
                if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
                {
                    Editor.Document.Selection.AddSelectionStart(startPosition);
                    Editor.Document.Selection.AddSelectionEnd(endPosition);
                }
            }
            else if (e.Key == Key.Back && Keyboard.Modifiers == ModifierKeys.Control)
            {
                if (!String.IsNullOrEmpty(Editor.Document.Selection.GetSelectedText()))
                {
                    Editor.Delete(true);
                }
                else
                {
 
                    DocumentPosition startPosition = Editor.Document.CaretPosition;
                    DocumentPosition endPosition = new DocumentPosition(startPosition);
                    startPosition.MoveToCurrentWordStart();
                    if (startPosition == endPosition)
                    {
                        startPosition.MoveToPreviousWordStart();
                        if (startPosition != endPosition)
                        {
                            Editor.Document.Selection.AddSelectionStart(startPosition);
                            Editor.Document.Selection.AddSelectionEnd(endPosition);
                            Editor.Delete(true);
                        }
                    }
                    else
                    {
                        Editor.Document.Selection.AddSelectionStart(startPosition);
                        Editor.Document.Selection.AddSelectionEnd(endPosition);
                        Editor.Delete(true);
                    }
                }
 
            }
            else if (e.Key == Key.Delete && Keyboard.Modifiers == ModifierKeys.Control)
            {
                if (!String.IsNullOrEmpty(Editor.Document.Selection.GetSelectedText()))
                {
                    Editor.Delete(true);
                }
                else
                {
                    DocumentPosition startPosition = Editor.Document.CaretPosition;
                    DocumentPosition endPosition = new DocumentPosition(startPosition);
                    startPosition.MoveToCurrentWordEnd();
                    if (startPosition == endPosition)
                    {
                        startPosition.MoveToNextWordStart();
                        startPosition.MoveToCurrentWordEnd();
                        if (startPosition != endPosition)
                        {
                            Editor.Document.Selection.AddSelectionStart(startPosition);
                            Editor.Document.Selection.AddSelectionEnd(endPosition);
                            Editor.Delete(false);
                        }
                    }
                    else
                    {
                        Editor.Document.Selection.AddSelectionStart(startPosition);
                        Editor.Document.Selection.AddSelectionEnd(endPosition);
                        Editor.Delete(false);
                    }
                }
            }
             
 
       
        }
0
danparker276
Top achievements
Rank 2
answered on 16 Jul 2013, 04:30 PM
Thanks Oleg, that works great.
0
danparker276
Top achievements
Rank 2
answered on 30 Jul 2013, 06:26 PM
One thing that needs to be changed on the example above is AddSelectionStart needs to be SetSelectionStart or you will get inline errors sometimes.

You can look at this thread about it:
http://www.telerik.com/community/forums/silverlight/richtextbox/re-selection-of-text-throws-inline-does-not-belong-to-this-document.aspx

This happens to me sometimes but not always.

The code should look like this:
                if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
                {
                    rrtbDescription.Document.Selection.SetSelectionStart(startPosition);
                    rrtbDescription.Document.Selection.AddSelectionEnd(endPosition);
                }
0
Iva Toteva
Telerik team
answered on 01 Aug 2013, 07:21 AM
Hello Dan,

Thank you for the follow-up. We are still not able to reproduce the issue and cannot tell what may be causing it.

However, some things that we noticed in the implementation above:

1. The code in the first two if-s implements functionality that is internally available and are not really needed. 

2. With regard to the rest of the code:
2.1. In general the choice between SetSelectionStart and AddSelectionStart depends on the behavior you wish to achieve. SetSelectionStart clears the current selection if any (what happens when you start selecting with the mouse and Ctrl is not pressed). AddSelectionStart starts a new selection range (the way Ctrl+Click and MouseMove works), keeping the selection in the editor. Neither of the two methods should throw an exception, provided that the passed document position is valid. However, SetSelectionStart makes more sense in this scenario in my opinion.

2.2. Moving the caret clears the current selection. For example in the snippets below:

DocumentPosition startPosition = Editor.Document.CaretPosition;
DocumentPosition endPosition = new DocumentPosition(startPosition);
startPosition.MoveToLastPositionInDocument();

startPosition is created as a reference to the caret position. Moving it (the last line of the snippet) moves the caret position as well, causing the current selection to be cleared. Thus, at this point there is no difference if AddSelectionStart or SetSelectionStart will be used with regard to the result.

2.3. When an action is executed, the internally implemented action on the occurrence of the same keys should be canceled:

e.SuppressDefaultAction = true;

Again, provided that we cannot reproduce the issue, we cannot recommend a way to avoid it. If you manage to isolate the problem in a stable manner, please get back to us with more details - sample document or a demo and steps to reproduce.


Regards,
Iva Toteva
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
danparker276
Top achievements
Rank 2
answered on 01 Aug 2013, 05:42 PM
I think things are good for now when I'm changing it to set.  I'll let you know if I see it again.  I wasn't even able to produce it on my end, just some of my customers saw the error.
Tags
RichTextBox
Asked by
Bryce
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Oleg
Top achievements
Rank 1
Boby
Telerik team
danparker276
Top achievements
Rank 2
Iva Toteva
Telerik team
Share this question
or