Menu

#347 upper, lower, title case

None
closed
nobody
1
2012-12-03
2012-10-25
No

As an editing feature, it would be very helpful to have the possibility of converting a selected string to uppercase, lowercase, or title-case. I.e.,
LIKE THIS,
like this,
or
Like This.

Thanks,
Dominik

Discussion

  • Tim Hoffmann

    Tim Hoffmann - 2012-11-04

    You can easily create user-defined macros for this (User -> Edit Macros):

    %SCRIPT
    cursor.replaceSelectedText(cursor.selectedText().toUpperCase())

    and similar ones. See the documentation for more on user macros.

    Since this feature is not very widely used, I wouldn't make it a dedicated operation built into TXS.

     
  • Tim Hoffmann

    Tim Hoffmann - 2012-11-04
    • status: open --> closed
    • milestone: -->
     
  • Anonymous

    Anonymous - 2012-12-03

    Thanks! The Upper case:

    %SCRIPT
    cursor.replaceSelectedText(cursor.selectedText().toUpperCase())

    and Lower case:

    %SCRIPT
    cursor.replaceSelectedText(cursor.selectedText().toLowerCase())

    are easy. Can someone help with the title case?

     
  • Anonymous

    Anonymous - 2012-12-03

    For example

    %SCRIPT
    function toTitleCase(str)
    {
        return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
    }
    
    cursor.replaceSelectedText(toTitleCase(cursor.selectedText()))
    
     

Anonymous
Anonymous

Add attachments
Cancel