簡體   English   中英

更改Flex 4中TextArea的文本選擇顏色以進行程序選擇

[英]Change text selection color for TextArea in Flex 4 for programmatic selection

我正在使用Flex 4 spark TextArea,並實現了搜索字段。 我使用以下代碼突出顯示TextArea中的搜索文本:

private function findAndHighlightText():void
    {
        var text:String = findTextInput.text;
        var beginIndex:int = scriptSourceTextArea.text.indexOf( text, m_lastFoundIndex );
        if (beginIndex == -1 && m_lastFoundIndex > 0)
        {
            // We are at the end, search back from the begin
            Alert.show( resourceManager.getString( 'groovyresources', 'search.at.end' ),
                        resourceManager.getString( 'groovyresources', 'find' ) );
            m_lastFoundIndex = 0;
            beginIndex = scriptSourceTextArea.text.indexOf( text, m_lastFoundIndex );
        }
        if (beginIndex != -1)
        {
            var endIndex:int = beginIndex + text.length;
            m_lastFoundIndex = endIndex;
            scriptSourceTextArea.selectRange( beginIndex, endIndex );
            scriptSourceTextArea.scrollToRange( beginIndex );
        }
        else
        {
            Alert.show( resourceManager.getString( 'groovyresources', 'search.not.found', [text] ),
                        resourceManager.getString( 'groovyresources', 'find' ) );
        }
    }

最重要的是TextArea上的selectRange方法。 這將突出顯示TextArea中的文本,但我想使用其他顏色。

我可以通過應用CSS樣式的focused-text-selection-color更改加亮顏色以進行手動選擇(請參見http://www.kirupa.com/forum/showthread.php?354479-Change-highlight-color-for-text -fields ),但這不會更改程序選擇的顏色。

更新:對於程序選擇,顏色不會更改,因為TextArea此時沒有焦點。 因此,我需要找到未聚焦的選擇顏色CSS名稱。

有兩種樣式會影響在Flex中突出顯示所選文本的方式:

    .scriptSourceTextArea {
        focused-text-selection-color: #788ec5;
        unfocused-text-selection-color: #7e94cb;
    }

一個用於焦點,另一個用於文本區域沒有焦點時。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM