write shit successfully

This commit is contained in:
2021-05-22 13:25:37 +08:00
parent 4aacc76a49
commit fc3e3906bc
8 changed files with 99 additions and 17 deletions

View File

@ -29,7 +29,11 @@ namespace BallanceTASEditor.Core {
Clipboard.SetDataObject(data, true);
}
return true;
#if DEBUG
} catch (Exception e) {
#else
} catch {
#endif
return false;
}
}
@ -55,7 +59,11 @@ namespace BallanceTASEditor.Core {
}
return true;
#if DEBUG
} catch (Exception e) {
#else
} catch {
#endif
return false;
}
}

View File

@ -92,7 +92,7 @@ namespace BallanceTASEditor.Core {
// if state is true, it mean the deleted content is placed before pointer previously.
// so we need shift the pointer to the head of selection range.
// and we should consider 2 situations, the full delete of LinkedList and delete from head
if (mPointerIndex <= absoluteRange.end) {
if (mPointerIndex >= absoluteRange.start) {
var newIndex = absoluteRange.start - 1;
if (newIndex < 0) {
// this contains 2 situation

View File

@ -8,6 +8,19 @@ using System.Text;
namespace BallanceTASEditor.Core {
public static class Util {
public static Int32 ToInt32(this double value) {
return (Int32)Math.Floor(value);
}
public static Int64 ToInt64(this double value) {
return (Int64)Math.Floor(value);
}
public static int Clamp(int value, int min, int max) {
if (value < min) return min;
if (value > max) return max;
return value;
}
public static bool ToBool(this UInt32 num) {
return (num != 0);
}
@ -29,11 +42,11 @@ namespace BallanceTASEditor.Core {
}
public static LinkedListNode<FrameData> FastGetNode(this LinkedList<FrameData> ls, LinkedListNode<FrameData> refNode, long refIndex, long targetIndex) {
long count = ls.Count;
if (targetIndex >= count || refIndex >= count) throw new Exception("Index is invalid!");
long count = ls.Count - 1;
if (targetIndex > count || refIndex > count) throw new Exception("Index is invalid!");
var span = new StupidSortStruct[3] {
new StupidSortStruct() { type = 1, data = targetIndex },
new StupidSortStruct() { type = 2, data = count - targetIndex },
new StupidSortStruct() { type = 2, data = targetIndex - count },
new StupidSortStruct() { type = 3, data = targetIndex - refIndex }
};