Skip to content

Commit

Permalink
change how constants are colored in the web editor
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Dec 21, 2023
1 parent 5574be1 commit 3a51c6e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion site/src/editor/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ fn set_code_html(id: &str, code: &str) {
.unwrap_or_default();
let class = if let Some(sig) = binding.global.signature() {
let margs = text.chars().rev().take_while(|c| *c == '!').count();
binding_class(text, sig, margs)
binding_class(text, sig, margs, binding.global.is_constant())
} else {
""
};
Expand Down
3 changes: 2 additions & 1 deletion site/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ fn prim_class(prim: Primitive) -> &'static str {
}
}

fn binding_class(name: &str, sig: Signature, margs: usize) -> &'static str {
fn binding_class(name: &str, sig: Signature, margs: usize, constant: bool) -> &'static str {
match name {
"Trans" => code_font!("trans text-gradient"),
"Bi" => code_font!("bi text-gradient"),
Expand All @@ -387,6 +387,7 @@ fn binding_class(name: &str, sig: Signature, margs: usize) -> &'static str {
"Nb" | "Enby" => code_font!("nb text-gradient"),
"Fluid" => code_font!("fluid text-gradient"),
"Queer" => code_font!("queer text-gradient"),
_ if constant => code_font!(""),
_ => match margs {
0 => match (sig.args, sig.outputs) {
(0, 1) => code_font!("noadic-function"),
Expand Down
8 changes: 8 additions & 0 deletions src/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ impl Global {
Self::Module { .. } => None,
}
}
/// Check if the global is a once-bound constant
pub fn is_constant(&self) -> bool {
match self {
Self::Const(_) => true,
Self::Sig(sig) if *sig == (0, 1) => true,
_ => false,
}
}
}

/// A repository of code strings input to the compiler
Expand Down

0 comments on commit 3a51c6e

Please sign in to comment.