aharui commented on issue #598: Spark TextArea does not show the content in Popup URL: https://github.com/apache/royale-asjs/issues/598#issuecomment-577477143 I'm still not clear on the details of some things like offset but here's a first cut at a MXTextArea- based component that can display line numbers next to some text. Test.mxml: ``` <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.apache.org/royale/spark" xmlns:mx="library://ns.apache.org/royale/mx" xmlns:local="*" creationComplete="loadData()" height="100%" width="100%" > <fx:Metadata> </fx:Metadata> <fx:Script> <![CDATA[ import mx.controls.Alert; protected var oldSearchResult:int = 0; public var returnXML:XML = <return> <code>0</code> <message> <data> <meta> <size>461</size> <name>conf\myraConfig.xml</name> </meta> <content> <myraConfig xmlns="http://www.likyateknoloji.com/myra-config"> <persistent>false</persistent> <normalize>true</normalize> <frequency>1</frequency> <higherThreshold>10</higherThreshold> <lowerThreshold>3</lowerThreshold> <logPath>./</logPath> <usejobnamesforlog>NO</usejobnamesforlog> <logFileExt>.log</logFileExt> <globalLogPath>./</globalLogPath> <logbuffersize>2000</logbuffersize> <logpagesize>10</logpagesize> </myraConfig> </content> </data> </message> </return>; public function loadData():void { var s:String = returnXML.toXMLString(); var fSize:int = returnXML.meta.size; fileSize.text = Math.round(s.length/1000) + "K"; mainTextField.text = s; callLater(setLineNumbers); } protected function button1_clickHandler(event:MouseEvent):void { var searchStr : String = searchTxt.text; var truncatedText : String; truncatedText = mainTextField.text.substring(oldSearchResult); var searchResult:int = truncatedText.search(searchStr); mainTextField.setFocus(); if(searchResult != -1) { var bIdx:int = oldSearchResult + searchResult; var eIdx:int = oldSearchResult + searchResult + searchStr.length; var pos:int = mainTextField.selectionActivePosition; mainTextField.selectRange(bIdx, eIdx); oldSearchResult = eIdx; mainTextField.scrollToRange(bIdx, oldSearchResult); setCaretPos(); setLineNumbers(); } else { Alert.show("search text not found"); } } protected function setCaretPos():void { activePosition.text = "[" + mainTextField.selectionActivePosition + "]"; } protected function setLineNumbers():void { var absoluteIndex : int = mainTextField.selectionActivePosition; var lineIdx : int = mainTextField.findLineIndexAtPosition(absoluteIndex); lineNumbers.text = (lineIdx + 1) + "/" + mainTextField.numLines; //endOff.value = 5000; } ]]> </fx:Script> <fx:Declarations> </fx:Declarations> <s:layout> <s:VerticalLayout gap="10" paddingRight="10" paddingLeft="10" paddingTop="10" paddingBottom="20" /> </s:layout> <mx:Panel title="Line Numbered Text Display Example" paddingBottom="10" paddingTop="10" paddingLeft="10" paddingRight="10" height="50%" width="50%"> <s:FormItem label="{resourceManager.getString('formatters', 'monthNamesShort')}" layout="{new HorizontalLayout()}" width="100%" > <mx:TextInput id="searchTxt" text="fname" /> <s:Button label="Search" click="button1_clickHandler(event)" /> </s:FormItem> <local:LineNumberTextDisplay id="mainTextField" height="100%" width="100%" /> <s:BorderContainer height="25" width="100%" backgroundColor="0xDCDCDC" borderStyle="solid"> <s:layout> <s:HorizontalLayout paddingLeft="5" paddingRight="5" paddingTop="5" paddingBottom="5" verticalAlign="middle"/> </s:layout> <s:Label text="Line Numbers:" /> <s:Label id="lineNumbers" /> <s:Spacer width="5%" /> <s:Label text="Caret Pos:" /> <s:Label id="activePosition" text="[0]" /> <s:Spacer width="100%" /> <s:HGroup horizontalAlign="right"> <s:Label text="File Size:" /> <s:Label id="fileSize" right="0" /> </s:HGroup> </s:BorderContainer> </mx:Panel> </s:Application> ``` LineNumberTextDisplay.mxml ``` <?xml version="1.0" encoding="utf-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.apache.org/royale/spark" xmlns:mx="library://ns.apache.org/royale/mx" horizontalGap="0" > <fx:Metadata> </fx:Metadata> <fx:Script> <![CDATA[ public function get text():String { return main.text; } public function set text(value:String):void { main.text = value; if (parent) setLineNumbers(); } public function get selectionActivePosition():int { return main.selectionBeginIndex; } public function set selectionActivePosition(value:int):void { main.selectionBeginIndex = value; } public function selectRange(begin:int, end:int):void { main.setSelection(begin, end); } public function scrollToRange(begin:int, end:int):void { } private var lineHeight:int = 0; public function get numLines():int { COMPILE::JS { if (!lineHeight) { var lineHeightStyle:String = getComputedStyle(element)["lineHeight"]; lineHeight = parseInt(lineHeightStyle, 10); } return Math.floor(main.element.scrollHeight / lineHeight); } return 0; } public function findLineIndexAtPosition(offset:int):int { return 0; } override public function addedToParent():void { super.addedToParent(); setLineNumbers(); COMPILE::JS { main.element.addEventListener("scroll", scrollHandler); } } public function setLineNumbers():void { var s:String = ""; var n:int = numLines; for (var i:int = 1; i <= n; i++) { s += i + "\n"; } numbers.text = s; } COMPILE::JS private function scrollHandler(event:Event):void { numbers.element.scrollTop = main.element.scrollTop; } ]]> </fx:Script> <fx:Declarations> </fx:Declarations> <mx:TextArea id="numbers" verticalScrollPolicy="off" horizontalScrollPolicy="off" height="100%" width="50"/> <mx:TextArea id="main" height="100%" width="100%" /> </mx:HBox> ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
