Skip to content

Commit ec63333

Browse files
committed
Tuning
1 parent 70b883b commit ec63333

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

docs/develop/standardsguidelines.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Github will pick up the changes so your PR stays up-to-date.
3838
> It has many subtle and unexpected consequences on our GitHub repository.
3939
> For example, we regularly lost review comments when the PR author force-pushes code changes. So, pretty please, do not force-push.
4040
41-
You can find a collection of very useful tips and tricks here: https://github.com/wled-dev/WLED/wiki/How-to-properly-submit-a-PR
41+
You can find a collection of very useful tips and tricks here: [How to properly submit a PR](https://github.com/wled-dev/WLED/wiki/How-to-properly-submit-a-PR)
4242

4343

4444
## Source Code from an AI agent or bot
@@ -52,11 +52,11 @@ You can find a collection of very useful tips and tricks here: https://github.co
5252
* If you don't feel very confident using English, you can use AI for translating code comments and descriptions into English. AI bots are very good at understanding language. However, always check if the results is correct. The translation might still have wrong technical terms, or errors in some details.
5353

5454
### best practice with AI:
55-
* As the person who contributes source code to MoonLight, make sure you understand exactly what the AI-generated code does
56-
@@ * best practice: add a comment like ``'// below section of my code was generated by an AI``, when larger parts of your source code were not written by you personally.
57-
* always review translations and code comments for correctness
58-
* always review AI-generated source code
59-
* If the AI has rewritten existing code, check that the change is necessary and that nothing has been lost or broken. Also check that previous code comments are still intact.
55+
* As the person who contributes source code to MoonLight, make sure you understand exactly what the AI-generated code does
56+
* best practice: add a comment like ``'// below section of my code was generated by an AI``, when larger parts of your source code were not written by you personally.
57+
* always review translations and code comments for correctness
58+
* always review AI-generated source code
59+
* If the AI has rewritten existing code, check that the change is necessary and that nothing has been lost or broken. Also check that previous code comments are still intact.
6060

6161
## Code style
6262

interface/src/lib/components/moonbase/MultiRow.svelte

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151
function handleReorder(reorderedItems: { item: any; originalIndex: number }[]) {
5252
console.log('handleReorder', property.name, reorderedItems);
5353
const full = [...data[property.name]];
54+
// Capture the current filteredItems mapping before any potential state changes
55+
const indexMap = filteredItems.map((f: any) => f.originalIndex);
5456
reorderedItems.forEach(({ item }, pos) => {
55-
const originalIndex = filteredItems[pos].originalIndex;
57+
const originalIndex = indexMap[pos];
5658
full[originalIndex] = item;
5759
});
5860
data[property.name] = full;
@@ -152,7 +154,7 @@
152154
<div class="h-16 flex w-full items-center justify-between space-x-3 p-0 text-xl font-medium">
153155
{initCap(property.name)}
154156
</div>
155-
{#if findItemInDefinition?.crud == null || findItemInDefinition.crud.includes('c')}
157+
{#if findItemInDefinition?.crud == null || findItemInDefinition?.crud?.includes('c')}
156158
<div class="relative w-full overflow-visible">
157159
<!-- <div class="mx-4 mb-4 flex flex-wrap justify-end gap-2"> -->
158160
<button
@@ -193,12 +195,12 @@
193195
items={filteredItems}
194196
onReorder={handleReorder}
195197
class="space-y-2"
196-
dragDisabled={!(findItemInDefinition?.crud == null || findItemInDefinition.crud.includes('s'))}
198+
dragDisabled={!(findItemInDefinition?.crud == null || findItemInDefinition?.crud?.includes('s'))}
197199
>
198200
{#snippet children({ item: itemWrapper }: { item: any })}
199201
<!-- svelte-ignore a11y_click_events_have_key_events -->
200202
<div class="rounded-box bg-base-100 flex items-center space-x-3 px-4 py-2">
201-
{#if findItemInDefinition?.crud == null || findItemInDefinition.crud.includes('s')}
203+
{#if findItemInDefinition?.crud == null || findItemInDefinition?.crud?.includes('s')}
202204
<Grip class="h-6 w-6 text-base-content/30 cursor-grab flex-shrink-0" />
203205
{/if}
204206
<!-- Show the first 3 fields -->
@@ -235,7 +237,7 @@
235237
>
236238
<SearchIcon class="h-6 w-6" /></button
237239
>
238-
{#if findItemInDefinition?.crud == null || findItemInDefinition.crud.includes('d')}
240+
{#if findItemInDefinition?.crud == null || findItemInDefinition?.crud?.includes('d')}
239241
<button
240242
class="btn btn-ghost btn-sm"
241243
onclick={() => {

src/MoonBase/Char.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#pragma once
1313

1414
#include <Arduino.h>
15+
1516
#include "ArduinoJson.h"
1617

1718
// See https://discord.com/channels/473448917040758787/718943978636050542/1357670679196991629
@@ -57,15 +58,6 @@ struct Char {
5758
// Or explicit to avoid implicit conversions:
5859
explicit operator const char*() const { return s; }
5960

60-
// concat operators
61-
// Char& operator+(const char* rhs) {
62-
// strlcat(s, rhs, sizeof(s));
63-
// return *this;
64-
// }
65-
// Char& operator+(const String& rhs) {
66-
// strlcat(s, rhs.c_str(), sizeof(s));
67-
// return *this;
68-
// }
6961
Char operator+(const char* rhs) const {
7062
Char result(*this);
7163
result += rhs;
@@ -85,23 +77,22 @@ struct Char {
8577
strlcat(s, rhs.c_str(), sizeof(s));
8678
return *this;
8779
}
88-
template <size_t M>
80+
template <size_t M>
8981
Char& operator+=(const Char<M>& rhs) {
9082
strlcat(s, rhs.c_str(), sizeof(s));
9183
return *this;
9284
}
9385

94-
9586
// compare operators
9687
bool operator==(const char* rhs) const { return strcmp(s, rhs) == 0; }
9788
bool operator==(const Char& rhs) const { return strcmp(s, rhs.s) == 0; }
9889
bool operator!=(const char* rhs) const { return strcmp(s, rhs) != 0; }
9990

100-
char operator[](const uint16_t indexV) const { return s[indexV]; }
91+
char operator[](const uint16_t indexV) const { return (indexV < sizeof(s)) ? s[indexV] : '\0'; }
10192

10293
Char<N> substring(uint16_t begin, uint16_t end = sizeof(s) - 1) {
10394
Char<N> sub;
104-
if (begin >= sizeof(s) || end >= sizeof(s))
95+
if (begin >= sizeof(s) || end >= sizeof(s) || end < begin)
10596
sub = "";
10697
else {
10798
strlcpy(sub.s, s + begin, end - begin + 1);

0 commit comments

Comments
 (0)