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

10 posts, 1 answers
  1. Bryce
    Bryce avatar
    32 posts
    Member since:
    Aug 2010

    Posted 12 Apr 2012 Link to this post

    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 
  2. Answer
    Martin Ivanov
    Admin
    Martin Ivanov avatar
    104 posts

    Posted 17 Apr 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. Oleg
    Oleg avatar
    42 posts
    Member since:
    Oct 2011

    Posted 17 Jan 2013 Link to this post

    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?
  5. Boby
    Admin
    Boby avatar
    595 posts

    Posted 18 Jan 2013 Link to this post

    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.

  6. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 15 Jul 2013 Link to this post

    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?
  7. Oleg
    Oleg avatar
    42 posts
    Member since:
    Oct 2011

    Posted 16 Jul 2013 Link to this post

    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);
                        }
                    }
                }
                 
     
           
            }
  8. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 16 Jul 2013 Link to this post

    Thanks Oleg, that works great.
  9. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 30 Jul 2013 Link to this post

    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);
                    }
  10. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 01 Aug 2013 Link to this post

    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 >>
  11. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 01 Aug 2013 Link to this post

    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.
Back to Top
DevCraft banner