handleRegionFields method
dynamic
handleRegionFields(
- FileIDE file
)
Implementation
handleRegionFields(FileIDE file) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
if (file.hasRegion) {
int regionStart = file.region.start!;
int regionEnd = file.region.end!;
if (prefs.get(file.id) != null) {
regionStart = int.parse(prefs.getString(file.id)?.split(':')[0] ?? '');
regionEnd = int.parse(prefs.getString(file.id)?.split(':')[1] ?? '');
}
int lines = file.content.split('\n').length;
if (lines >= 1) {
String beforeEditableRegionText =
file.content.split('\n').sublist(0, regionStart).join('\n');
String inEditableRegionText = file.content
.split('\n')
.sublist(regionStart, regionEnd - 1)
.join('\n');
String afterEditableRegionText = file.content
.split('\n')
.sublist(regionEnd - 1, file.content.split('\n').length)
.join('\n');
beforeController.text = beforeEditableRegionText;
inController.text = inEditableRegionText;
afterController.text = afterEditableRegionText;
}
} else {
beforeController.text = '';
inController.text = file.content;
afterController.text = '';
}
updateLineCount(inController.text, RegionPosition.inner);
}