Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
matefun
Frontend
Commits
d5a7f16f
Commit
d5a7f16f
authored
Feb 18, 2019
by
Franco Pariani
Browse files
Finding functions that matches with the clicked word
parent
430ee10f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Frontend Angular 4/src/app/layout/matefun/codemirror/matefun-mode-EN.js
View file @
d5a7f16f
...
...
@@ -28,6 +28,7 @@
const
hintWords
=
require
(
'
./hint_words
'
);
var
WORD
=
/
[\w
$
]
+/
;
var
RANGE
=
500
;
var
SET
=
/set
\s
+
([\w\_\d]
+
)\s
*
\=
/
;
var
DOM
=
/
\:\:
/
;
...
...
@@ -37,7 +38,59 @@
var
WRITING_SET
=
/set
\s
/
;
var
WRITING_COMMENT
=
/
\{\-
/
;
var
RANGE
=
500
;
// functions definitions
CodeMirror
.
defineExtension
(
"
functionDefinition
"
,
function
(
editor
,
options
)
{
var
word
=
options
&&
options
.
word
||
WORD
;
var
range
=
options
&&
options
.
range
||
RANGE
;
var
cur
=
editor
.
getCursor
(),
curLine
=
editor
.
getLine
(
cur
.
line
);
var
end
=
cur
.
ch
,
start
=
end
;
while
(
start
&&
word
.
test
(
curLine
.
charAt
(
start
-
1
)))
--
start
;
while
(
end
&&
word
.
test
(
curLine
.
charAt
(
end
+
1
)))
++
end
;
var
curWord
=
start
!=
end
&&
curLine
.
slice
(
start
,
end
+
1
);
if
(
curWord
.
length
>
0
){
var
list
=
[],
seen
=
{};
var
re_digits
=
new
RegExp
(
/^
\d
+$/
,
"
g
"
);
var
re_funs
=
new
RegExp
(
FUNS
.
source
,
"
g
"
);
for
(
var
dir
=
-
1
;
dir
<=
1
;
dir
+=
2
)
{
var
line
=
cur
.
line
,
endLine
=
Math
.
min
(
Math
.
max
(
line
+
dir
*
range
,
editor
.
firstLine
()),
editor
.
lastLine
())
+
dir
;
for
(;
line
!=
endLine
;
line
+=
dir
)
{
var
text
=
editor
.
getLine
(
line
),
m
;
while
(
m
=
re_funs
.
exec
(
text
))
{
if
(
!
re_digits
.
exec
(
m
[
1
])
&&
(
!
curWord
||
m
[
1
]
==
curWord
)
&&
!
Object
.
prototype
.
hasOwnProperty
.
call
(
seen
,
m
[
1
]))
{
seen
[
m
[
1
]]
=
true
;
list
.
push
(
m
[
1
]);
}
}
}
}
console
.
log
(
list
);
}
/*options = parseOptions(this, this.getCursor("start"), options);
var selections = this.listSelections()
if (selections.length > 1) return;
// By default, don't allow completion when something is selected.
// A hint function can have a `supportsSelection` property to
// indicate that it can handle selections.
if (this.somethingSelected()) {
if (!options.hint.supportsSelection) return;
// Don't try with cross-line selections
for (var i = 0; i < selections.length; i++)
if (selections[i].head.line != selections[i].anchor.line) return;
}
if (this.state.completionActive) this.state.completionActive.close();
var completion = this.state.completionActive = new Completion(this, options);
if (!completion.options.hint) return;
CodeMirror.signal(this, "startCompletion", this);
completion.update(true);*/
});
// hints
CodeMirror
.
registerHelper
(
"
hint
"
,
"
anyword
"
,
function
(
editor
,
options
)
{
var
word
=
options
&&
options
.
word
||
WORD
;
...
...
Frontend Angular 4/src/app/layout/matefun/matefun.component.html
View file @
d5a7f16f
...
...
@@ -135,7 +135,7 @@
</ng-template>
</form>
</div>
<codemirror
class=
"codemirrorPrograma"
[(ngModel)]=
"archivo.contenido"
(keyup)=
"archivoModificado($event)"
[config]=
"configCodeMirror"
[ngStyle]=
"{'font-size': configCodeMirror.fontSize+'px'}"
>
<codemirror
class=
"codemirrorPrograma"
[(ngModel)]=
"archivo.contenido"
(keyup)=
"archivoModificado($event)"
(click)=
"clickEnEditor($event)"
[config]=
"configCodeMirror"
[ngStyle]=
"{'font-size': configCodeMirror.fontSize+'px'}"
>
</codemirror>
</div>
...
...
Frontend Angular 4/src/app/layout/matefun/matefun.component.ts
View file @
d5a7f16f
...
...
@@ -456,6 +456,10 @@ export class MateFunComponent {
this
.
codemirror
.
instance
.
toggleComment
();
}
clickEnEditor
(
event
){
this
.
codemirror
.
instance
.
functionDefinition
(
this
.
codemirror
.
instance
.
doc
,
event
);
}
guardarArchivo
(){
var
regex
=
/^
[
A-Z
]
/
if
(
this
.
archivo
.
nombre
.
trim
()
==
""
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment