Skip to content

Commit

Permalink
working log viewer find text
Browse files Browse the repository at this point in the history
  • Loading branch information
hagaygo committed Feb 5, 2023
1 parent a16609d commit cb191a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 0 additions & 8 deletions lib/Page/Form/deviceActionForm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,6 @@ class DeviceActionFormState extends State<DeviceActionForm> {

void showLogPage(String title, LogViewerForm logView) {
Dialogs.showPage(context, title, logView, useListView: false, actions: <Widget>[
IconButton(
onPressed: () {
// var lst = logView.getCurrentLines();
// var idx = lst.indexOf("[ 0.004845] Zone ranges:");
// var scrollX = (idx * 12).toDouble();
// logView.scroll(scrollX, 0);
},
icon: Icon(Icons.search)),
IconButton(
icon: Icon(
Icons.refresh,
Expand Down
24 changes: 16 additions & 8 deletions lib/Page/Form/logViewerForm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ class LogViewerForm extends StatefulWidget {
return _state._currentLines;
}

void scroll(double y, double x) {
_state.verticalScrollController.animateTo(y, duration: Duration(milliseconds: 500), curve: Curves.ease);
}

void refresh() {
_state.refresh();
}
Expand All @@ -35,6 +31,7 @@ class LogViewerFormState extends State<LogViewerForm> {
List<Widget> lst = [];

var textSpans = <TextSpan>[];
_foundTextLines = [];
int counter = 0;
for (var line in _currentLines) {
if (_searchText != null && _searchText.length > 0 && line.contains(_searchText)) {
Expand Down Expand Up @@ -88,7 +85,6 @@ class LogViewerFormState extends State<LogViewerForm> {

ScrollController verticalScrollController = ScrollController();
ScrollController horizontalScrollController = ScrollController();
String _lastSearchText;
int _lastFoundIndex = 0;

final searchTextController = TextEditingController();
Expand All @@ -109,16 +105,28 @@ class LogViewerFormState extends State<LogViewerForm> {
IconButton(
onPressed: () {
setState(() {
_searchText = searchTextController.text;
if (_searchText != searchTextController.text) {
_lastFoundIndex = 0;
_searchText = searchTextController.text;
}
getLines().then((l) {
_lines = l;
if (_foundTextLines.length > 0) {
verticalScrollController.jumpTo((_foundTextLines[0] * 12).toDouble());
if (_lastFoundIndex >= _foundTextLines.length) _lastFoundIndex = 0;
var lineHeight =
(verticalScrollController.position.maxScrollExtent / _currentLines.length).floor();
verticalScrollController.jumpTo((verticalScrollController.position.viewportDimension +
_foundTextLines[_lastFoundIndex] * lineHeight)
.toDouble());
_lastFoundIndex++;
}
});
});
},
icon: Icon(Icons.search))
icon: Icon(Icons.search)),
Visibility(
visible: _foundTextLines.length > 0,
child: Text(_lastFoundIndex.toString() + "/" + _foundTextLines.length.toString()))
],
)),
Expanded(
Expand Down

0 comments on commit cb191a4

Please sign in to comment.