Skip to content

Instantly share code, notes, and snippets.

@GiuseppeChillemi
Created September 26, 2023 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GiuseppeChillemi/fa86ce950459120e8bda1419da4c2319 to your computer and use it in GitHub Desktop.
Save GiuseppeChillemi/fa86ce950459120e8bda1419da4c2319 to your computer and use it in GitHub Desktop.
Bug on multiple clicks with take and insert on head
Red [
Title: "This is a bug test for with"
Description: "it generates not enough memmory"
]
;
;#include %scripts-rebol/add-word.red
;#include %scripts-rebol/get-start-end.red
;#include %scripts-rebol/select-and-store2.red
;======================= ADD A WORDS TO AREA ==================
add-word: func [
"Adds a word to the top or to the bottom of a string"
target [String!]
txt2 [string!]
mode [word!]
/top
/local
] [
;Append to area/text a the text found and a newline (to the end) or inser to the head the new text found and a newline
;--If modes is 'newline, we append the cut text in TXT2 to the text area
if mode = 'newline [
either not top [
;prin "add word: "
append target rejoin [txt2 newline]
;prin "txt2: " probe head txt2
] [
;--- We insear tat the head if TOP is ative
insert head target rejoin [target newline] ;Copy not needed
]
]
;As before without a newline
if mode = 'single [
either not top [
append target txt2
][
insert head target copy txt2
]
]
]
;================================================================
get-start-end: func [
"Returns a PAIR with start and position at key found"
series [string!]
search-key [string! char!]
] [
attempt [to-pair reduce [index? series index? find series search-key]]
]
;================================================================
select-and-store: func [
"Select the first line of a window and store into a target string"
window [object!] "The window"
target [string!] "The target string"
/top
/local
mode
focused-face
search-key
line
pos
end-select
] [
search-key: lf
focused-face: window
end-select: false
;--- we add the text at the bottom or at the top
;
mode: 'newline ;'newline or 'single
;--- Here we focus to see the selection, because focus il lost after our selection
set-focus focused-face
;--- If there is a selection STORE
either pair? focused-face/selected [
;--- Copy and removes part of a text and sotre it in the target
line: take/part at focused-face/text focused-face/selected/1 focused-face/selected/2
;TBD: Remove Lf only if over a value to preserve at least 1 newline?
;
attempt [take/part focused-face/text skip-text focused-face/text search-key]
set-focus focused-face
either not top [
add-word target line mode
] [
add-word/top target line mode
]
focused-face/selected: get-start-end focused-face/text search-key
] [
focused-face/selected: get-start-end focused-face/text search-key
]
]
;===============================================================
str: copy ""
str2: copy ""
lv: copy []
repeat idx 10000 [
line: "test-testlgkfnrwekerghfeirjhkgliuewrhgliuewlhkgrbffvukjebrliukerbvkiejrhbekirhvbtest-testlgkfnrwekerghfeirjhkgliuewrhgliuewlhkgrbffvukjebrliukerbvkiejrhbekirhvb^/"
line2: "328472093850293850924750t347t05723502975097230579203975023975092375092375097207b328472093850293850924750t347t05723502975097230579203975023975092375092375097207b^/"
append lv rejoin [to-string idx "-" line]
append str rejoin [to-string idx "-" line]
append str2 rejoin [to-string idx "-" line2]
]
last-focused-area: none
area3-name: "mooood"
view layout [
style note: Area 400x150 "" on-down [last-focused-area: face] on-mid-down [
view selection-window
]
a1: note str2 with [extra: make object! [note-name: none myname: none label-face: area3-name] ]
a2: note str2 with [extra: make object! [note-name: none myname: none label-face: area3-name] ]
a3: note str2 with [extra: make object! [note-name: none myname: none label-face: area3-name] ]
return
a4: note str with [extra: make object! [note-name: none myname: none label-face: area3-name] ]
a5: note 400x500 str with [extra: make object! [note-name: none myname: none label-face: area3-name] ]
below
pad 100x40
text "Click-below continuosly!" 150x20
text-list 400x300 data lv on-change [
select-and-store/top a3 str
face/selected: none
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment