comigor / fuzzy

Fuzzy search in Dart
MIT License
37 stars 20 forks source link

Range error when using limit argument to fuse.search #25

Open bradleybauer opened 2 years ago

bradleybauer commented 2 years ago

To avoid this error

RangeError (end): Invalid value: Not in inclusive range 0..1: 15

When the exception was thrown, this was the stack:
#0      RangeError.checkValidRange (dart:core/errors.dart:356:9)
#1      List.sublist (dart:core-patch/growable_array.dart:84:38)
#2      Fuzzy.search (package:fuzzy/fuzzy.dart:58:40)
#3      MyFilterSearch.search (package:EveIndy/search.dart:17:25)
#4      _SearchBarState.build.<anonymous closure> (package:EveIndy/gui/widgets/search_bar.dart:40:18)
#5      EditableTextState._formatAndSetValue (package:flutter/src/widgets/editable_text.dart:2630:27)
#6      EditableTextState.updateEditingValue (package:flutter/src/widgets/editable_text.dart:1967:7)
#7      TextInput._handleTextInputInvocation (package:flutter/src/services/text_input.dart:1730:37)
#8      MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:404:55)
#9      MethodChannel.setMethodCallHandler.<anonymous closure>
(package:flutter/src/services/platform_channel.dart:397:34)
#10     _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:380:35)
#11     _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:377:46)
#12     _invoke2.<anonymous closure> (dart:ui/hooks.dart:190:15)
#16     _invoke2 (dart:ui/hooks.dart:189:10)
#17     _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:42:5)
#18     _Channel.push (dart:ui/channel_buffers.dart:132:31)
#19     ChannelBuffers.push (dart:ui/channel_buffers.dart:329:17)
#20     PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:589:22)
#21     _dispatchPlatformMessage (dart:ui/hooks.dart:89:31)
(elided 3 frames from dart:async)

This line

https://github.com/comigor/fuzzy/blob/f4135f6552aeaa8c25238ed4ab32475bf148a69c/lib/fuzzy.dart#L58

should be changed to

if (limit > 0 && resultsAndWeights.results.length > limit) {