mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-06-27 00:00:46 -04:00
veilid-server now defaults to waiting for port 5150
This commit is contained in:
parent
5b26dc8b13
commit
deaff56232
2 changed files with 98 additions and 12 deletions
|
@ -0,0 +1,69 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// TextField History Controller
|
||||
class HistoryTextEditingController {
|
||||
HistoryTextEditingController(
|
||||
{required this.setState, TextEditingController? controller})
|
||||
: _controller = controller ?? TextEditingController() {
|
||||
_historyFocusNode = FocusNode(onKeyEvent: (_node, event) {
|
||||
if (event.runtimeType == KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.arrowUp) {
|
||||
if (_historyPosition > 0) {
|
||||
if (_historyPosition == _history.length) {
|
||||
_historyCurrentEdit = _controller.text;
|
||||
}
|
||||
_historyPosition -= 1;
|
||||
setState(() {
|
||||
_controller.text = _history[_historyPosition];
|
||||
});
|
||||
}
|
||||
return KeyEventResult.handled;
|
||||
} else if (event.runtimeType == KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.arrowDown) {
|
||||
if (_historyPosition < _history.length) {
|
||||
_historyPosition += 1;
|
||||
setState(() {
|
||||
if (_historyPosition == _history.length) {
|
||||
_controller.text = _historyCurrentEdit;
|
||||
} else {
|
||||
_controller.text = _history[_historyPosition];
|
||||
}
|
||||
});
|
||||
}
|
||||
return KeyEventResult.handled;
|
||||
} else if (event.runtimeType == KeyDownEvent) {
|
||||
_historyPosition = _history.length;
|
||||
_historyCurrentEdit = _controller.text;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
});
|
||||
}
|
||||
|
||||
void submit(String v) {
|
||||
// add to history
|
||||
if (_history.isEmpty || _history.last != v) {
|
||||
_history.add(v);
|
||||
if (_history.length > 100) {
|
||||
_history.removeAt(0);
|
||||
}
|
||||
}
|
||||
_historyPosition = _history.length;
|
||||
setState(() {
|
||||
_controller.text = '';
|
||||
});
|
||||
}
|
||||
|
||||
FocusNode get focusNode => _historyFocusNode;
|
||||
TextEditingController get controller => _controller;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
late void Function(void Function()) setState;
|
||||
final TextEditingController _controller;
|
||||
late final FocusNode _historyFocusNode;
|
||||
|
||||
final List<String> _history = [];
|
||||
int _historyPosition = 0;
|
||||
String _historyCurrentEdit = '';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue